rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.22k stars 12.56k forks source link

ICE thread 'rustc' panicked at 'index out of bounds: the len is 8 but the index is 18446744073709551615' #41394

Closed SimonSapin closed 7 years ago

SimonSapin commented 7 years ago

Building Servo with rustc 1.18.0-nightly (467aaab50 2017-04-19):

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'index out of bounds: the len is 8 but the index is 18446744073709551615', /checkout/src/libcollections/vec.rs:1484
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:60
             at /checkout/src/libstd/panicking.rs:355
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:365
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:549
   5: std::panicking::begin_panic
             at /checkout/src/libstd/panicking.rs:511
   6: std::panicking::begin_panic_fmt
             at /checkout/src/libstd/panicking.rs:495
   7: rust_begin_unwind
             at /checkout/src/libstd/panicking.rs:471
   8: core::panicking::panic_fmt
             at /checkout/src/libcore/panicking.rs:69
   9: core::panicking::panic_bounds_check
             at /checkout/src/libcore/panicking.rs:56
  10: rustc::ty::AdtDef::discriminant_for_variant
  11: rustc_trans::mir::rvalue::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_rvalue
  12: rustc_trans::mir::block::<impl rustc_trans::mir::MirContext<'a, 'tcx>>::trans_block
  13: rustc_trans::mir::trans_mir
  14: rustc_trans::trans_item::TransItem::define
  15: rustc_trans::base::trans_crate
  16: rustc_driver::driver::phase_4_translate_to_llvm
  17: rustc_driver::driver::compile_input::{{closure}}
  18: rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}
  19: rustc::ty::context::TyCtxt::create_and_enter
  20: rustc_driver::driver::phase_3_run_analysis_passes
  21: rustc_driver::driver::compile_input
  22: rustc_driver::run_compiler
  23: std::panicking::try::do_call
  24: __rust_maybe_catch_panic
             at /checkout/src/libpanic_unwind/lib.rs:98
  25: <F as alloc::boxed::FnBox<A>>::call_box
  26: std::sys::imp::thread::Thread::new::thread_start
             at /checkout/src/liballoc/boxed.rs:650
             at /checkout/src/libstd/sys_common/thread.rs:21
             at /checkout/src/libstd/sys/unix/thread.rs:84
  27: start_thread
  28: __clone

error: Could not compile `script`.

For what it’s worth, 18446744073709551615 is 0xFFFF_FFFF_FFFF_FFFF.

SimonSapin commented 7 years ago

https://github.com/rust-lang/rust/blob/467aaab50ef0c7284121d59d8f7af3184836e586/src/librustc/ty/mod.rs#L1710

       loop {
            match self.variants[explicit_index].discr {
                ty::VariantDiscr::Relative(0) => break,
                ty::VariantDiscr::Relative(distance) => {
                    explicit_index -= distance;
                }
                ty::VariantDiscr::Explicit(expr_did) => {
                    match queries::monomorphic_const_eval::get(tcx, DUMMY_SP, expr_did) {
                        Ok(ConstVal::Integral(v)) => {
                            explicit_value = v;
                            break;
                        }
                        _ => {
                            explicit_index -= 1;
                        }
                    }
                }
            }
SimonSapin commented 7 years ago

This whole method was added in https://github.com/rust-lang/rust/pull/41310. CC @eddyb

eddyb commented 7 years ago

@SimonSapin Do you get no error before this ICE? I see what I did wrong, but this can only be triggered by the first variant having an explicit discriminant which errored during evaluation.

SimonSapin commented 7 years ago

No other error, the output before what’s in the initial message is:

% RUST_BACKTRACE=1 mach build
   Compiling script v0.0.1 (file:///home/simon/servo1/components/script)
warning: variable does not need to be mutable
   --> /home/simon/servo1/target/debug/build/script-9370d82a1d46a1f2/out/Bindings/MutationObserverBinding.rs:483:17
    |
483 |             let mut argc = 2;
    |                 ^^^^^^^^
    |
    = note: #[warn(unused_mut)] on by default

error: internal compiler error: unexpected panic
arielb1 commented 7 years ago

@eddyb are you looking at this?

eddyb commented 7 years ago

@arielb1 I'm pretty sure I know the fix but I fear that this is a different bug that trans hid before, and we'd hide again. I'm trying to get Servo people to find the enum with 8 variants and explicit discriminant(s).

eddyb commented 7 years ago

Looks like ValueTag::INT32 fails to evaluate without producing an error. JSValueType::JSVAL_TYPE_INT32 is just 1 so the evaluation should have succeeded.

eddyb commented 7 years ago

Oh, evaluation fails because of #23898 - which I've accidentally extended the incidence of. I've fixed it on a branch, guess that will be the fix for this bug as well, just need @est31 to confirm.

eddyb commented 7 years ago

Minimal testcase of the actual ICE bug (amusingly, it requires the fix for #23898 to trigger):

enum Foo {
    A = "" + 1
}

enum Bar {
    A = Foo::A as isize
}