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 in const_prop.rs:633: 'index out of bounds: the len is 1 but the index is 1' #66339

Closed
bytwise opened this issue Nov 12, 2019 · 2 comments · Fixed by #67015
Closed

ICE in const_prop.rs:633: 'index out of bounds: the len is 1 but the index is 1' #66339

bytwise opened this issue Nov 12, 2019 · 2 comments · Fixed by #67015
Assignees
Labels
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) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bytwise
Copy link
Contributor

bytwise commented Nov 12, 2019

This code results in an ICE when compiling using -Z mir-opt-level=3.

trait Write {
    fn write();
}

impl Write for () {
    fn write() {
        let none = |_| { None };
        let _: Option<()> = none("blink");
    }
}
thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', src/librustc_mir/transform/const_prop.rs:633:42
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::continue_panic_fmt
   8: rust_begin_unwind
   9: core::panicking::panic_fmt
  10: core::panicking::panic_bounds_check
  11: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement
  12: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
  13: rustc_mir::transform::run_passes
  14: rustc_mir::transform::run_optimization_passes
  15: rustc_mir::transform::optimized_mir
  16: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
  17: rustc::dep_graph::graph::DepGraph::with_task_impl
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  19: rustc_mir::monomorphize::collector::collect_items_rec
  20: rustc_mir::monomorphize::collector::collect_crate_mono_items::{{closure}}
  21: rustc::util::common::time
  22: rustc_mir::monomorphize::collector::collect_crate_mono_items
  23: rustc::util::common::time
  24: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  25: rustc::ty::query::__query_compute::collect_and_partition_mono_items
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  28: rustc_codegen_ssa::base::codegen_crate
  29: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  30: rustc_interface::passes::start_codegen::{{closure}}
  31: rustc_interface::passes::start_codegen
  32: rustc::ty::context::tls::enter_global
  33: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  34: rustc_interface::passes::create_global_ctxt::{{closure}}
  35: rustc_interface::passes::BoxedGlobalCtxt::enter
  36: rustc_interface::queries::Query<T>::compute
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::ongoing_codegen
  38: rustc_interface::interface::run_compiler_in_existing_thread_pool
  39: std::thread::local::LocalKey<T>::with
  40: scoped_tls::ScopedKey<T>::set
  41: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.40.0-nightly (3fc30d884 2019-11-10) running on x86_64-apple-darwin

note: compiler flags: -Z mir-opt-level=3 -C opt-level=3 --crate-type lib

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

query stack during panic:
#0 [optimized_mir] processing `<() as Write>::write`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
@Centril Centril added 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. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Nov 12, 2019
@Centril
Copy link
Contributor

Centril commented Nov 12, 2019

cc @wesleywiser @oli-obk

@wesleywiser wesleywiser self-assigned this Nov 12, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Nov 13, 2019
@VirrageS
Copy link
Contributor

Reduced:

fn foo() {
    let bar = |_| { };
    let _ = bar("a");
}

But this compiles:

fn foo() {
    let bar = |_, _| { };
    let _ = bar("a", "b");
}

@wesleywiser wesleywiser added the requires-nightly This issue requires a nightly compiler in some way. label Dec 6, 2019
Centril added a commit to Centril/rust that referenced this issue Dec 11, 2019
Fix constant propagation for scalar pairs

We now only propagate a scalar pair if the Rvalue is a tuple with two scalars. This for example avoids propagating a (u8, u8) value when Rvalue has type `((), u8, u8)` (see the regression test). While this is a correct thing to do, implementation is tricky and will be done later.

Fixes rust-lang#66971
Fixes rust-lang#66339
Fixes rust-lang#67019
@bors bors closed this as completed in 2404a06 Dec 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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) ❄️ requires-nightly This issue requires a nightly compiler in some way. 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