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 with const generics with disabled feature flag #69913

Closed
Patryk27 opened this issue Mar 11, 2020 · 5 comments
Closed

ICE with const generics with disabled feature flag #69913

Patryk27 opened this issue Mar 11, 2020 · 5 comments
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. const-generics-fixed-by-const_generics A bug that has been fixed once `const_generics` is enabled. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. 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

@Patryk27
Copy link
Contributor

Patryk27 commented Mar 11, 2020

Hi,

Following code ICEs on stable (1.41.1), beta (1.42.0-beta.6) and nightly (2020-03-10):

fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {
    //
}

(playground)

The issue arises when:

  • an expression in used in place of array size ([usize; A + B] in this case),
  • and code generics are not enabled explicitly (notice missing feature attribute),
Backtrace

   Compiling playground v0.0.1 (/playground)
error[E0658]: const generics are unstable
 --> src/lib.rs:1:14
  |
1 | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {
  |              ^
  |
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
  = help: add `#![feature(const_generics)]` to the crate attributes to enable

error[E0658]: const generics are unstable
 --> src/lib.rs:1:30
  |
1 | fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {
  |                              ^
  |
  = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
  = help: add `#![feature(const_generics)]` to the crate attributes to enable

error: internal compiler error: src/librustc/ty/subst.rs:605: const parameter `A/#0` (Const { ty: usize, val: Param(A/#0) }/0) out of range when substituting substs=[]

thread 'rustc' panicked at 'Box<Any>', src/librustc/lib.rs:1:1
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1063
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::span_bug
  14: rustc_errors::Handler::span_bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::span_bug_fmt
  20: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const
  21: rustc::ty::normalize_erasing_regions::<impl rustc::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  22: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand
  23: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
  24: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
  25: rustc_mir::const_eval::eval_queries::const_eval_raw_provider
  26: rustc::ty::query::__query_compute::const_eval_raw
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  30: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  31: rustc::ty::query::__query_compute::const_eval_validated
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  36: rustc::ty::query::__query_compute::const_eval_validated
  37: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  40: rustc::mir::interpret::queries::<impl rustc::ty::context::TyCtxt>::const_eval_resolve
  41: rustc::ty::sty::Const::eval::{{closure}}
  42: rustc::ty::sty::Const::eval
  43: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
  44: <rustc_infer::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty
  45: rustc::ty::structural_impls::fold_list
  46: rustc_infer::traits::project::normalize
  47: rustc_infer::infer::InferCtxt::partially_normalize_associated_types_in
  48: rustc::ty::context::GlobalCtxt::enter_local
  49: rustc_typeck::check::wfcheck::check_item_well_formed
  50: rustc::ty::query::__query_compute::check_item_well_formed
  51: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute
  52: rustc::dep_graph::graph::DepGraph::with_task_impl
  53: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  54: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  55: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  56: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  57: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:86
  58: rustc_hir::hir::Crate::par_visit_all_item_likes
  59: rustc_typeck::check_crate
  60: rustc_interface::passes::analysis
  61: rustc::ty::query::__query_compute::analysis
  62: rustc::dep_graph::graph::DepGraph::with_task_impl
  63: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  64: rustc::ty::context::tls::enter_global
  65: rustc_interface::interface::run_compiler_in_existing_thread_pool
  66: scoped_tls::ScopedKey<T>::set
  67: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.43.0-nightly (158127853 2020-03-10) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

query stack during panic:
#0 [const_eval_raw] const-evaluating `foo::{{constant}}#0`
#1 [const_eval_validated] const-evaluating + checking `foo::{{constant}}#0`
#2 [const_eval_validated] const-evaluating + checking `foo::{{constant}}#0`
#3 [check_item_well_formed] processing `foo`
#4 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.

@Patryk27 Patryk27 added C-bug Category: This is a bug. 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. labels Mar 11, 2020
@Centril Centril added F-const_generics `#![feature(const_generics)]` A-const-generics Area: const generics (parameters and arguments) labels Mar 11, 2020
@chrissimpkins
Copy link
Member

chrissimpkins commented Mar 11, 2020

Source:

fn foo<const A: usize, const B: usize>(bar: [usize; A + B]) {
    //
}

Godbolt shows that the ICE occurs in 1.39.0 and not in 1.38.0.

cargo bisect-rustc indicates that the regression is in nightly-2019-08-21. We're outside of the 167 day CI date range window to bisect at the commit level with the tool.

Here is the commit dump:

commit[0] 2019-08-19UTC: Auto merge of #63579 - alexcrichton:new-lockfile, r=Mark-Simulacrum
commit[1] 2019-08-19UTC: Auto merge of #63715 - Centril:rollup-dga8qtp, r=Centril
commit[2] 2019-08-20UTC: Auto merge of #62727 - SimonSapin:plugins-tls-dylib, r=petrochenkov
commit[3] 2019-08-20UTC: Auto merge of #63497 - eddyb:miri-subst, r=oli-obk
commit[4] 2019-08-20UTC: Auto merge of #63709 - matklad:decomposed-tokens, r=petrochenkov
commit[5] 2019-08-20UTC: Auto merge of #63587 - flip1995:clippyup, r=flip1995
commit[6] 2019-08-20UTC: Auto merge of #63744 - Centril:rollup-g4l3ra9, r=Centril
commit[7] 2019-08-20UTC: Auto merge of #63752 - Centril:rollup-nlxwety, r=Centril

@lcnr
Copy link
Contributor

lcnr commented Mar 18, 2020

@rustbot claim

@lcnr
Copy link
Contributor

lcnr commented Mar 29, 2020

will be fixed by lazy normalization.
@rustbot release-assignment

@rustbot rustbot removed their assignment Mar 29, 2020
@varkor varkor added the A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) label Apr 8, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Oct 5, 2020
…lcnr,estebank

Fix missing diagnostic span for `impl Trait` with const generics, and add various tests for `min_const_generics` and `const_generics`

Closes rust-lang#61410.

Adds `min_const_generics` tests for:
- rust-lang#73727
- rust-lang#72293
- rust-lang#67375
- rust-lang#75153
- rust-lang#71922
- rust-lang#69913
- rust-lang#67945
- rust-lang#69239

Adds `const_generics` tests for:
- rust-lang#67375
- rust-lang#75153
- rust-lang#71922
- rust-lang#69913
- rust-lang#67945
- rust-lang#69239

(I only added separate `min_const_generics` and `const_generics` tests if they were handled differently by the two features.)

We need to figure out how to deduplicate when `const_generics` is stabilised, but we can discuss that later. For now, we should be checking neither feature breaks, so require regression tests for both. I've given them identical names when I've added both, which should make it easier to spot them later.

r? @lcnr
@JohnTitor
Copy link
Member

Triage:
This is no longer ICE even with the const_generics feature flag: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=8069684ce72997079d8933e6e758fece

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 30, 2020
@lcnr
Copy link
Contributor

lcnr commented Dec 30, 2020

we already have a bunch of similar tests, closing without adding an an additional one

@lcnr lcnr closed this as completed Dec 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) A-lazy-normalization Area: Lazy normalization (tracking issue: #60471) C-bug Category: This is a bug. const-generics-fixed-by-const_generics A bug that has been fixed once `const_generics` is enabled. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_generics `#![feature(const_generics)]` glacier ICE tracked in rust-lang/glacier. 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
Development

Successfully merging a pull request may close this issue.

8 participants