Skip to content
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

"Broken MIR" ICE while creating array with const generic length from single value #61336

Closed
carado opened this issue May 30, 2019 · 6 comments · Fixed by #61698, #61805 or #63497
Closed

"Broken MIR" ICE while creating array with const generic length from single value #61336

carado opened this issue May 30, 2019 · 6 comments · Fixed by #61698, #61805 or #63497
Assignees
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html 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.

Comments

@carado
Copy link

carado commented May 30, 2019

A clean project with this code:

#![feature(const_generics)]

fn f<T: Copy /* ICE's just as badly without Copy */, const N: usize>(x: T) -> [T; N] {
	[x; N]
}

fn main() {}

Produces this error:

    Checking rust5 v0.1.0 (/home/carado/tmp/rust5)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', /rustc/37d001e4deb206ed954fde5d91690221e8306fc3/src/libcore/slice/mod.rs:2695:10
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:197
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   6: rustc::util::common::panic_hook
   7: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   8: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   9: rust_begin_unwind
             at src/libstd/panicking.rs:308
  10: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  11: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
  12: rustc_mir::borrow_check::nll::type_check::type_check
  13: rustc_mir::borrow_check::nll::compute_regions
  14: rustc_mir::borrow_check::do_mir_borrowck
  15: rustc::ty::context::GlobalCtxt::enter_local
  16: rustc_mir::borrow_check::mir_borrowck
  17: rustc::ty::query::__query_compute::mir_borrowck
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::mir_borrowck>::compute
  19: rustc::dep_graph::graph::DepGraph::with_task_impl
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  21: rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners
  22: rustc::util::common::time
  23: rustc_interface::passes::analysis
  24: rustc::ty::query::__query_compute::analysis
  25: rustc::dep_graph::graph::DepGraph::with_task_impl
  26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  27: rustc::ty::context::tls::enter_global
  28: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  29: rustc_interface::passes::create_global_ctxt::{{closure}}
  30: rustc_interface::interface::run_compiler_in_existing_thread_pool
  31: std::thread::local::LocalKey<T>::with
  32: scoped_tls::ScopedKey<T>::set
  33: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [mir_borrowck] processing `f`
#1 [analysis] running analysis passes on this crate
end of query stack
error: internal compiler error: cat_expr Errd
 --> src/main.rs:3:47
  |
3 |   fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
  |  _______________________________________________^
4 | |     [x; N]
5 | | }
  | |_^

error: internal compiler error: cat_expr Errd
 --> src/main.rs:4:2
  |
4 |     [x; N]
  |     ^^^^^^

error: internal compiler error: QualifyAndPromoteConstants: MIR had errors
 --> src/main.rs:3:1
  |
3 | / fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
4 | |     [x; N]
5 | | }
  | |_^

error: internal compiler error: broken MIR in DefId(0:12 ~ rust5[a994]::f[0]) ("return type"): bad type [type error]
 --> src/main.rs:3:1
  |
3 | / fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
4 | |     [x; N]
5 | | }
  | |_^

error: internal compiler error: broken MIR in DefId(0:12 ~ rust5[a994]::f[0]) (LocalDecl { mutability: Mut, is_user_variable: None, internal: false, is_block_tail: None, ty: [type error], user_ty: UserTypeProjections { contents: [] }, name: None, source_info: SourceInfo { span: src/main.rs:3:1: 5:2, scope: scope[0] }, visibility_scope: scope[0] }): bad type [type error]
 --> src/main.rs:3:1
  |
3 | / fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
4 | |     [x; N]
5 | | }
  | |_^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src/librustc_errors/lib.rs:356:17
stack backtrace:
   0:     0x7eff9d7fbcfa - backtrace::backtrace::libunwind::trace::h27e79239ae132594
                               at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/libunwind.rs:97
   1:     0x7eff9d7fbcfa - backtrace::backtrace::trace_unsynchronized::h4d06032f1d31ea4f
                               at /cargo/registry/src/github.heygears.com-1ecc6299db9ec823/backtrace-0.3.25/src/backtrace/mod.rs:66
   2:     0x7eff9d7fbcfa - std::sys_common::backtrace::_print::h87f958e4afa789cc
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7eff9d7fbcfa - std::sys_common::backtrace::print::h9701366bda361a82
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7eff9d7fbcfa - std::panicking::default_hook::{{closure}}::hdeb6e1bffcdd7ad2
                               at src/libstd/panicking.rs:197
   5:     0x7eff9d7fb9fb - std::panicking::default_hook::hda59c88c4e0c7e8b
                               at src/libstd/panicking.rs:211
   6:     0x7eff9b5774c0 - rustc::util::common::panic_hook::h5c18c3a9efba48a4
   7:     0x7eff9d7fc558 - std::panicking::rust_panic_with_hook::hb309d4b58eca6d76
                               at src/libstd/panicking.rs:478
   8:     0x7eff9a1eaf04 - std::panicking::begin_panic::h4630c81ce88a3b0e
   9:     0x7eff9a205cb4 - <rustc_errors::Handler as core::ops::drop::Drop>::drop::h72e0d28e271712f9
  10:     0x7eff9db28951 - core::ptr::real_drop_in_place::h2f95b5568cdff1bc
  11:     0x7eff9db32a30 - core::ptr::real_drop_in_place::hf9944cf4ccd8b0f9
  12:     0x7eff9db34b03 - <alloc::rc::Rc<T> as core::ops::drop::Drop>::drop::h9ab61e1d23124c65
  13:     0x7eff9dafc9ab - core::ptr::real_drop_in_place::h500d402def4b18fe
  14:     0x7eff9dafa3f6 - rustc_interface::interface::run_compiler_in_existing_thread_pool::hdc9adcf187c1c745
  15:     0x7eff9db62a45 - std::thread::local::LocalKey<T>::with::hb4d77454d8f5b39f
  16:     0x7eff9db10304 - scoped_tls::ScopedKey<T>::set::hf0af9addd0db626a
  17:     0x7eff9db25103 - syntax::with_globals::hf05470816f33fc03
  18:     0x7eff9db53d2c - std::sys_common::backtrace::__rust_begin_short_backtrace::hfd0071cd5db5cd9e
  19:     0x7eff9d80d499 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:85
  20:     0x7eff9dadde58 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h101536dc4ddcc287
  21:     0x7eff9d7dfa9e - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h08bd7d4edd708d24
                               at /rustc/37d001e4deb206ed954fde5d91690221e8306fc3/src/liballoc/boxed.rs:746
  22:     0x7eff9d80c16f - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::he2a07dcda49e9385
                               at /rustc/37d001e4deb206ed954fde5d91690221e8306fc3/src/liballoc/boxed.rs:746
  23:     0x7eff9d80c16f - std::sys_common::thread::start_thread::h9f229612a1fc41e1
                               at src/libstd/sys_common/thread.rs:13
  24:     0x7eff9d80c16f - std::sys::unix::thread::Thread::new::thread_start::h5b2c91946063a815
                               at src/libstd/sys/unix/thread.rs:79
  25:     0x7eff9d743fa7 - start_thread
                               at /builddir/glibc-2.29/nptl/pthread_create.c:486
  26:     0x7eff9d665a1e - __GI___clone
  27:                0x0 - <unknown>
query stack during panic:
end of query stack
thread panicked while panicking. aborting.
error: Could not compile `rust5`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name rust5 src/main.rs --color always --crate-type bin --emit=dep-info,metadata -C debuginfo=2 -C metadata=a524629e5b525adf -C extra-filename=-a524629e5b525adf --out-dir /home/carado/tmp/rust5/target/debug/deps -C incremental=/home/carado/tmp/rust5/target/debug/incremental -L dependency=/home/carado/tmp/rust5/target/debug/deps` (signal: 4, SIGILL: illegal instruction)
@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-const-generics Area: const generics (parameters and arguments) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels May 30, 2019
@Centril
Copy link
Contributor

Centril commented May 30, 2019

cc @varkor (const generics) @oli-obk (qualification)

@varkor
Copy link
Member

varkor commented May 31, 2019

I think this is possibly down to #49147 not being implemented.

@Centril
Copy link
Contributor

Centril commented Jun 1, 2019

cc @davidtwco You may want to consider this as part of the work on [X; N].

Centril added a commit to Centril/rust that referenced this issue Jun 11, 2019
… r=varkor

typeck: Fix const generic in repeat param ICE.

Fixes rust-lang#61336. Turns out this wasn't related to rust-lang#49147 after all.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 11, 2019
… r=varkor

typeck: Fix const generic in repeat param ICE.

Fixes rust-lang#61336. Turns out this wasn't related to rust-lang#49147 after all.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 11, 2019
… r=varkor

typeck: Fix const generic in repeat param ICE.

Fixes rust-lang#61336. Turns out this wasn't related to rust-lang#49147 after all.

r? @varkor
@c410-f3r
Copy link
Contributor

Same as #61514, the compiler still crashes with brackets:

#![feature(const_generics)]

fn f<T: Copy /* ICE's just as badly without Copy */, const N: usize>(x: T) -> [T; N] {
	[x; {N}]
}

fn main() {}

@varkor varkor reopened this Jun 13, 2019
@varkor varkor added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Jun 13, 2019
Centril added a commit to Centril/rust that referenced this issue Jun 14, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 14, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 14, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 14, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 14, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 14, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
Centril added a commit to Centril/rust that referenced this issue Jun 15, 2019
…expr-count-sequel, r=varkor

typeck: Fix ICE for blocks in repeat expr count.

Fixes rust-lang#61336 (again). This PR fixes an ICE that occured when a block expression resolving to a const generic was used for the count of an array repeat expression.

r? @varkor
@eddyb
Copy link
Member

eddyb commented Aug 12, 2019

I don't understand, how was this fixed without running into #43408?
Special-casing a const generic param as an array length expression?

Then why do I still see the array length expression that depends on a const generic param in #63497, causing the telltale signs of #43408, via ICE?

@eddyb
Copy link
Member

eddyb commented Aug 12, 2019

I think that a full fix for this would involve adding Node::AnonConst(_) to this (i.e. the fix for #43408) but only if the workaround applies (because in that case, the cyclic issues of #43408 shouldn't trigger)

Node::Ctor(..) | Node::Field(_) => {

@eddyb eddyb reopened this Aug 12, 2019
@eddyb eddyb self-assigned this Aug 12, 2019
Centril added a commit to Centril/rust that referenced this issue Aug 20, 2019
rustc_mir: fix miri substitution/"universe" discipline.

Alternative to rust-lang#61041, based on @RalfJung's own attempt at it.
I haven't done a full audit, but I believe everything is fixed now.

Fixes rust-lang#61432.
Closes rust-lang#61336, as a drive-by fix (for a subset of rust-lang#43408, that is already special-cased).

r? @oli-obk / @RalfJung cc @varkor @yodaldevoid
@bors bors closed this as completed in 7858dc2 Aug 20, 2019
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html 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.
Projects
None yet
5 participants