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: tcx: index out of bounds: the len is 6 but the index is 6 #120940

Closed
matthiaskrgr opened this issue Feb 11, 2024 · 1 comment · Fixed by #120944
Closed

ICE: tcx: index out of bounds: the len is 6 but the index is 6 #120940

matthiaskrgr opened this issue Feb 11, 2024 · 1 comment · Fixed by #120944
Assignees
Labels
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

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(fn_traits, unboxed_closures)]
struct Foo<T>(T);

impl<T: Copy> Fn<()> for Foo<T> {
    fn call(&self, _: ()) -> T {
        match *self {
            Foo(t) => t,
        }
    }
}

impl<T: Copy> FnMut<()> for Foo<T> {}

impl<T: Copy> FnOnce<()> for Foo<T> {
    type Output = T;

    fn call_once(self, _: ()) -> T {
        self.call(())
    }
}

original:

// run-pass
#![feature(fn_traits, unboxed_closures)]
struct Foo<T>(T);

impl<T: Copy> Fn<()> for Foo<T> {
    extern "vectorcall" fn call(&self, _: ()) -> T {
      match *self {
        Foo(t) => t
      }
    }
}

impl<T: Copy> FnMut<()> for Foo<T> {
    extern "rust-call" fn call_mut(&mut self, _: ()) -> T {
        self.call(())
    }
}

impl<T: Copy> FnOnce<()> for Foo<T> {
    type Output = T;

    extern "rust-call" fn call_once(self, _: ()) -> T {
        self.call(())
    }
}

fn main() {
  let t: u8 = 1;
  println!("{}", Foo(t)());
}

Version information

rustc 1.78.0-nightly (9aa232ecc 2024-02-11)
binary: rustc
commit-hash: 9aa232ecc7bb006a1fad404f437b049482021a3a
commit-date: 2024-02-11
host: x86_64-unknown-linux-gnu
release: 1.78.0-nightly
LLVM version: 17.0.6

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-opt-level=0 -Zpolymorphize=on -Zinline-mir=yes

Program output

error[E0601]: `main` function not found in crate `mvce`
  --> /tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs:20:2
   |
20 | }
   |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs`

error[E0053]: method `call` has an incompatible type for trait
 --> /tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs:5:5
  |
5 |     fn call(&self, _: ()) -> T {
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "rust-call" fn, found "Rust" fn
  |
  = note: expected signature `extern "rust-call" fn(&Foo<_>, ()) -> _`
             found signature `fn(&Foo<_>, ()) -> _`

error[E0046]: not all trait items implemented, missing: `call_mut`
  --> /tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs:12:1
   |
12 | impl<T: Copy> FnMut<()> for Foo<T> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `call_mut` in implementation
   |
   = help: implement the missing item: `fn call_mut(&mut self, _: ()) -> <Self as FnOnce<()>>::Output { todo!() }`

error[E0053]: method `call_once` has an incompatible type for trait
  --> /tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs:17:5
   |
17 |     fn call_once(self, _: ()) -> T {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "rust-call" fn, found "Rust" fn
   |
   = note: expected signature `extern "rust-call" fn(Foo<_>, ()) -> _`
              found signature `fn(Foo<_>, ()) -> _`

thread 'rustc' panicked at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/compiler/rustc_middle/src/mir/tcx.rs:133:61:
index out of bounds: the len is 6 but the index is 6
stack backtrace:
   0:     0x7f87783e2416 - std::backtrace_rs::backtrace::libunwind::trace::haa332446d2816da1
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5
   1:     0x7f87783e2416 - std::backtrace_rs::backtrace::trace_unsynchronized::hc79ac4bb87de99b7
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f87783e2416 - std::sys_common::backtrace::_print_fmt::h826e31038d6fed55
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f87783e2416 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h7d45101adaea8e2e
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f8778434f90 - core::fmt::rt::Argument::fmt::habb091c2e565929c
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/fmt/rt.rs:142:9
   5:     0x7f8778434f90 - core::fmt::write::h430cd915198bfbfa
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/fmt/mod.rs:1120:17
   6:     0x7f87783d5c9f - std::io::Write::write_fmt::h76a4f85596572687
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/io/mod.rs:1854:15
   7:     0x7f87783e21f4 - std::sys_common::backtrace::_print::h730103227e62d0c1
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f87783e21f4 - std::sys_common::backtrace::print::h4b37a0052f447bb6
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f87783e4fe7 - std::panicking::default_hook::{{closure}}::h9ce01cf4995c297e
  10:     0x7f87783e4d49 - std::panicking::default_hook::h82708ac75720d681
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:292:9
  11:     0x7f877514999c - std[2504e1f5e79dbd0a]::panicking::update_hook::<alloc[4e175fcaaf6bf4c3]::boxed::Box<rustc_driver_impl[f5849ce36d1a60d2]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f87783e5736 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h9c044ab60f052747
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/alloc/src/boxed.rs:2030:9
  13:     0x7f87783e5736 - std::panicking::rust_panic_with_hook::h47b07230e93314a2
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:785:13
  14:     0x7f87783e5482 - std::panicking::begin_panic_handler::{{closure}}::h6c5fbc890ce207d0
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:659:13
  15:     0x7f87783e2916 - std::sys_common::backtrace::__rust_end_short_backtrace::hec2f82c01fee32cd
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7f87783e51d4 - rust_begin_unwind
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/panicking.rs:647:5
  17:     0x7f87784316e5 - core::panicking::panic_fmt::h48a1a0d3500755c9
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/panicking.rs:72:14
  18:     0x7f8778431932 - core::panicking::panic_bounds_check::h9c1f082d9b7cb73f
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/core/src/panicking.rs:208:5
  19:     0x7f8776def5d5 - rustc_const_eval[1987f47b2cdff49e]::transform::validate::validate_types
  20:     0x7f8776b8c65f - <rustc_const_eval[1987f47b2cdff49e]::transform::validate::Validator as rustc_middle[dddd7df0b25e8df]::mir::MirPass>::run_pass
  21:     0x7f8776410bf9 - rustc_mir_transform[156c0abd78acfd74]::pass_manager::run_passes_inner
  22:     0x7f877692882a - rustc_mir_transform[156c0abd78acfd74]::optimized_mir
  23:     0x7f877647a535 - rustc_query_impl[6d1f17dd37feccf6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d1f17dd37feccf6]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 8usize]>>
  24:     0x7f877647abe1 - rustc_query_system[e40b0ad2841d92dc]::query::plumbing::try_execute_query::<rustc_query_impl[6d1f17dd37feccf6]::DynamicConfig<rustc_query_system[e40b0ad2841d92dc]::query::caches::DefIdCache<rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[6d1f17dd37feccf6]::plumbing::QueryCtxt, false>
  25:     0x7f877647a35e - rustc_query_impl[6d1f17dd37feccf6]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  26:     0x7f87767b3d9b - rustc_middle[dddd7df0b25e8df]::query::plumbing::query_get_at::<rustc_query_system[e40b0ad2841d92dc]::query::caches::DefIdCache<rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 8usize]>>>
  27:     0x7f8776e1dba4 - rustc_query_impl[6d1f17dd37feccf6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d1f17dd37feccf6]::query_impl::unused_generic_params::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 4usize]>>
  28:     0x7f8776e1d36e - rustc_query_system[e40b0ad2841d92dc]::query::plumbing::try_execute_query::<rustc_query_impl[6d1f17dd37feccf6]::DynamicConfig<rustc_query_system[e40b0ad2841d92dc]::query::caches::DefaultCache<rustc_middle[dddd7df0b25e8df]::ty::instance::InstanceDef, rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[6d1f17dd37feccf6]::plumbing::QueryCtxt, false>
  29:     0x7f8776e1d052 - rustc_query_impl[6d1f17dd37feccf6]::query_impl::unused_generic_params::get_query_non_incr::__rust_end_short_backtrace
  30:     0x7f8776e18cf8 - rustc_interface[614167ae26197186]::passes::analysis
  31:     0x7f8776e182df - rustc_query_impl[6d1f17dd37feccf6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[6d1f17dd37feccf6]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 1usize]>>
  32:     0x7f8776ed2d64 - rustc_query_system[e40b0ad2841d92dc]::query::plumbing::try_execute_query::<rustc_query_impl[6d1f17dd37feccf6]::DynamicConfig<rustc_query_system[e40b0ad2841d92dc]::query::caches::SingleCache<rustc_middle[dddd7df0b25e8df]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[6d1f17dd37feccf6]::plumbing::QueryCtxt, false>
  33:     0x7f8776ed2ac7 - rustc_query_impl[6d1f17dd37feccf6]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  34:     0x7f877713006f - rustc_interface[614167ae26197186]::interface::run_compiler::<core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>, rustc_driver_impl[f5849ce36d1a60d2]::run_compiler::{closure#0}>::{closure#0}
  35:     0x7f877736e0d2 - std[2504e1f5e79dbd0a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[614167ae26197186]::util::run_in_thread_with_globals<rustc_interface[614167ae26197186]::util::run_in_thread_pool_with_globals<rustc_interface[614167ae26197186]::interface::run_compiler<core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>, rustc_driver_impl[f5849ce36d1a60d2]::run_compiler::{closure#0}>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>
  36:     0x7f877736defe - <<std[2504e1f5e79dbd0a]::thread::Builder>::spawn_unchecked_<rustc_interface[614167ae26197186]::util::run_in_thread_with_globals<rustc_interface[614167ae26197186]::util::run_in_thread_pool_with_globals<rustc_interface[614167ae26197186]::interface::run_compiler<core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>, rustc_driver_impl[f5849ce36d1a60d2]::run_compiler::{closure#0}>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[ae955e53bd86118a]::result::Result<(), rustc_span[5816d1300c2c104a]::ErrorGuaranteed>>::{closure#1} as core[ae955e53bd86118a]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x7f87783ee925 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3205da42e967968e
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/alloc/src/boxed.rs:2016:9
  38:     0x7f87783ee925 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3a8d804b35a578bc
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/alloc/src/boxed.rs:2016:9
  39:     0x7f87783ee925 - std::sys::pal::unix::thread::Thread::new::thread_start::ha87a0836a03cdbad
                               at /rustc/9aa232ecc7bb006a1fad404f437b049482021a3a/library/std/src/sys/pal/unix/thread.rs:108:17
  40:     0x7f87722aa9eb - <unknown>
  41:     0x7f877232e7cc - <unknown>
  42:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.78.0-nightly (9aa232ecc 2024-02-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-opt-level=0 -Z polymorphize=on -Z inline-mir=yes -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<impl at /tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs:14:1: 14:36>::call_once`
#1 [unused_generic_params] determining which generic parameters are unused by `<impl at /tmp/icemaker_global_tempdir.u1pxKPNyM6gY/rustc_testrunner_tmpdir_reporting.NfvSAW9e4CZU/mvce.rs:14:1: 14:36>::call_once`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0046, E0053, E0601.
For more information about an error, try `rustc --explain E0046`.

@matthiaskrgr matthiaskrgr 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. C-bug Category: This is a bug. labels Feb 11, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 11, 2024
@matthiaskrgr
Copy link
Member Author

#120550 cc @oli-obk

@oli-obk oli-obk added requires-nightly This issue requires a nightly compiler in some way. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 11, 2024
@compiler-errors compiler-errors self-assigned this Feb 11, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2024
Check that the ABI of the instance we are inlining is correct

When computing the `CallSite` in the mir inliner, double check that the instance of the function that we are inlining is compatible with the signature from the trait definition that we acquire from the MIR.

Fixes rust-lang#120940

r? `@oli-obk` or `@cjgillot`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 12, 2024
…-obk

Check that the ABI of the instance we are inlining is correct

When computing the `CallSite` in the mir inliner, double check that the instance of the function that we are inlining is compatible with the signature from the trait definition that we acquire from the MIR.

Fixes rust-lang#120940

r? `@oli-obk` or `@cjgillot`
@bors bors closed this as completed in 8ec144d Feb 12, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 12, 2024
Rollup merge of rust-lang#120944 - compiler-errors:inliner-abi, r=oli-obk

Check that the ABI of the instance we are inlining is correct

When computing the `CallSite` in the mir inliner, double check that the instance of the function that we are inlining is compatible with the signature from the trait definition that we acquire from the MIR.

Fixes rust-lang#120940

r? ``@oli-obk`` or ``@cjgillot``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

4 participants