Skip to content

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

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
SimonSapin opened this issue Apr 19, 2017 · 9 comments · Fixed by #41408
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@SimonSapin
Copy link
Contributor

Building Servo with rustc 1.18.0-nightly (467aaab 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
Copy link
Contributor Author

pub fn discriminant_for_variant(&self,

       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
Copy link
Contributor Author

This whole method was added in #41310. CC @eddyb

@eddyb
Copy link
Member

eddyb commented Apr 19, 2017

@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
Copy link
Contributor Author

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 arielb1 added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Apr 19, 2017
@arielb1
Copy link
Contributor

arielb1 commented Apr 19, 2017

@eddyb are you looking at this?

@eddyb
Copy link
Member

eddyb commented Apr 19, 2017

@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
Copy link
Member

eddyb commented Apr 19, 2017

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
Copy link
Member

eddyb commented Apr 19, 2017

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
Copy link
Member

eddyb commented Apr 19, 2017

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
}

bors added a commit that referenced this issue Apr 23, 2017
rustc: generalize monomorphic_const_eval to polymorphic constants.

With the addition of `Substs` to the query key, we can now evaluate *and cache* polymorphic constants.

Fixes #23898 by replacing the crippled explicit-discriminant-only local-crate-only `lookup_variant_by_id` with `ConstVal::Variant` which can describe variants irrespective of their discriminant.

Fixes #41394 by fixing #23898 (for the original testcase) and by not looping past the first discriminant.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants