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

Recursive fn with varying const generic parameter causes ICE. #64048

Closed
goddessfreya opened this issue Aug 31, 2019 · 3 comments
Closed

Recursive fn with varying const generic parameter causes ICE. #64048

goddessfreya opened this issue Aug 31, 2019 · 3 comments

Comments

@goddessfreya
Copy link
Contributor

#![feature(const_generics)]

fn mk_array<T, const TO: usize>() -> [T; TO] {
    panic!();
}

fn uperms<const DICE_NUM: usize>() -> Vec<[u8; DICE_NUM]> {
    if DICE_NUM <= 1 {
        return vec![mk_array::<u8, {DICE_NUM}>()];
    } else {
        let pperms = uperms::<{ DICE_NUM - 1 }>();
        panic!();
    }
}

fn main() {
    let perms1 = uperms::<{ 1 }>();
}

Play link

Backtrace:

   Compiling farklemaster v0.1.0 (/home/gentz/Documents/gfx/farklemaster)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^
  |
  = note: `#[warn(incomplete_features)]` on by default

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

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:578:9
stack backtrace:
   0:     0x7fbf7a370902 - backtrace::backtrace::libunwind::trace::h4ce370bcd1ee6179
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.35/src/backtrace/libunwind.rs:88
   1:     0x7fbf7a370902 - backtrace::backtrace::trace_unsynchronized::ha1849ec6dc042df0
                               at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.35/src/backtrace/mod.rs:66
   2:     0x7fbf7a370902 - std::sys_common::backtrace::_print::hb67777a898188c39
                               at src/libstd/sys_common/backtrace.rs:47
   3:     0x7fbf7a370902 - std::sys_common::backtrace::print::hadbba928c72abbae
                               at src/libstd/sys_common/backtrace.rs:36
   4:     0x7fbf7a370902 - std::panicking::default_hook::{{closure}}::h277bed7d7e46968e
                               at src/libstd/panicking.rs:200
   5:     0x7fbf7a3705e6 - std::panicking::default_hook::hc04dc2fea0cc3aac
                               at src/libstd/panicking.rs:214
   6:     0x7fbf7c24da31 - rustc::util::common::panic_hook::hadd0b8f85b4067ef
   7:     0x7fbf7a37113c - std::panicking::rust_panic_with_hook::h7ed0ac6f9e15991f
                               at src/libstd/panicking.rs:481
   8:     0x7fbf7c1dc53d - std::panicking::begin_panic::h1c40c95922eba485
   9:     0x7fbf7bd1e9ad - rustc_errors::Handler::span_bug::hac0d34a0564a9731
  10:     0x7fbf7befe51e - rustc::util::bug::opt_span_bug_fmt::{{closure}}::h139ee24d6fa9531e
  11:     0x7fbf7bef8ed3 - rustc::ty::context::tls::with_opt::{{closure}}::h4c0650730b3d87b0
  12:     0x7fbf7bef8e43 - rustc::ty::context::tls::with_context_opt::h0b052a3db2fd7393
  13:     0x7fbf7bef8e87 - rustc::ty::context::tls::with_opt::h0247b58216cb47e8
  14:     0x7fbf7befe428 - rustc::util::bug::opt_span_bug_fmt::h3dc854d51555accb
  15:     0x7fbf7befe3da - rustc::util::bug::span_bug_fmt::h6a2695b88c32fe61
  16:     0x7fbf7bd086fb - <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const::h7e3469995479b33a
  17:     0x7fbf7b2cee00 - rustc::traits::codegen::<impl rustc::ty::context::TyCtxt>::subst_and_normalize_erasing_regions::he1889485709b37ce
  18:     0x7fbf7b44b907 - rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand::hb2ea8eb42ae9cf9e
  19:     0x7fbf7b45758b - rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run::h2c4cd78b015ece1f
  20:     0x7fbf7b23711a - rustc_mir::const_eval::const_eval_raw_provider::hf3ff85bb694929ee
  21:     0x7fbf7b2ed073 - rustc::ty::query::__query_compute::const_eval_raw::h5ba229962fe4016d
  22:     0x7fbf7b24515a - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute::h565e5bce23bd5cf5
  23:     0x7fbf7b3a2f6a - rustc::dep_graph::graph::DepGraph::with_task_impl::ha30d8a9044e56636
  24:     0x7fbf7b26bbd5 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h37ea358b8ec9d7c6
  25:     0x7fbf7b235c6e - rustc_mir::const_eval::const_eval_provider::h792d7cb0f1f28534
  26:     0x7fbf7b2ec463 - rustc::ty::query::__query_compute::const_eval::hefa01c0bd68294d6
  27:     0x7fbf7b244f6a - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute::h6bb6e558896acff8
  28:     0x7fbf7b3a444d - rustc::dep_graph::graph::DepGraph::with_task_impl::hac6e9df0a3e6f199
  29:     0x7fbf7b267350 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h3025814bdb98c9f5
  30:     0x7fbf7b235bfc - rustc_mir::const_eval::const_eval_provider::h792d7cb0f1f28534
  31:     0x7fbf7bd1693a - rustc::ty::query::__query_compute::const_eval::hb4aa5926d8dc5c9d
  32:     0x7fbf7c10f44a - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval>::compute::h6bb6e558896acff8
  33:     0x7fbf7bc68f39 - rustc::dep_graph::graph::DepGraph::with_task_impl::h69bc137031276732
  34:     0x7fbf7bf7f3a7 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h36bdc4fed882ea78
  35:     0x7fbf7c16adee - rustc::ty::sty::Const::eval::hb401cdbfd953e0ba
  36:     0x7fbf7bd3401d - <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter::he9e2ab7fd3307967
  37:     0x7fbf7c15773b - rustc::ty::fold::TypeFoldable::fold_with::haa043f760b7edf82
  38:     0x7fbf7c14daee - <rustc::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty::h86a6eb69d7cae1d0
  39:     0x7fbf7b0113e4 - rustc::traits::project::normalize::hcd8ad6288aa2ebc9
  40:     0x7fbf7ae452cd - rustc_typeck::check::FnCtxt::instantiate_value_path::hedaf5ff2b8b867b2
  41:     0x7fbf7ae0bf30 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind::hf72747da8aab128d
  42:     0x7fbf7ae08ee5 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hd4290fcb743dc65a
  43:     0x7fbf7ae24603 - rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call::h543b73b94215b502
  44:     0x7fbf7ae0991e - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind::hf72747da8aab128d
  45:     0x7fbf7ae08ee5 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hd4290fcb743dc65a
  46:     0x7fbf7ae40dd1 - rustc_typeck::check::FnCtxt::check_decl_initializer::h0df3aa7cb5f326b2
  47:     0x7fbf7ae40e85 - rustc_typeck::check::FnCtxt::check_decl_local::h16dc6a267bb855a1
  48:     0x7fbf7ae40f9b - rustc_typeck::check::FnCtxt::check_stmt::hb8d30f7fa9c2c1f7
  49:     0x7fbf7ae4142b - rustc_typeck::check::FnCtxt::check_block_with_expected::h272b260cd492369d
  50:     0x7fbf7ae08ee5 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hd4290fcb743dc65a
  51:     0x7fbf7adf1a7f - rustc_typeck::check::_match::<impl rustc_typeck::check::FnCtxt>::check_match::hd3b0418651de0d88
  52:     0x7fbf7ae09d40 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind::hf72747da8aab128d
  53:     0x7fbf7ae08ee5 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hd4290fcb743dc65a
  54:     0x7fbf7ae4146b - rustc_typeck::check::FnCtxt::check_block_with_expected::h272b260cd492369d
  55:     0x7fbf7ae08ee5 - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation_and_needs::hd4290fcb743dc65a
  56:     0x7fbf7ae135fb - rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr::h9a52a562d86b5052
  57:     0x7fbf7ae2ed25 - rustc_typeck::check::check_fn::hcb029ffa950299ec
  58:     0x7fbf7af9c709 - rustc::ty::context::GlobalCtxt::enter_local::hcc1e02c358261193
  59:     0x7fbf7ae2dcb8 - rustc_typeck::check::typeck_tables_of::h6f0eb1f8c7b9f5e9
  60:     0x7fbf7ae7ddca - rustc::ty::query::__query_compute::typeck_tables_of::h62d65d4026b99e27
  61:     0x7fbf7af10fcb - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::typeck_tables_of>::compute::hca69de331eee9759
  62:     0x7fbf7aeb7d02 - rustc::dep_graph::graph::DepGraph::with_task_impl::ha7be3be332b95d17
  63:     0x7fbf7af20931 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h10565f1243b7ad5c
  64:     0x7fbf7af0dd7f - rustc::ty::<impl rustc::ty::context::TyCtxt>::par_body_owners::h3a830552646698d8
  65:     0x7fbf7ae2d72d - rustc_typeck::check::typeck_item_bodies::h7b6a9b66bd0d82f5
  66:     0x7fbf7ae7e215 - rustc::ty::query::__query_compute::typeck_item_bodies::hd0a39d56e65efaff
  67:     0x7fbf7aeb9004 - rustc::dep_graph::graph::DepGraph::with_task_impl::hb953ebfe5f7d123d
  68:     0x7fbf7af2c6dd - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::h25e7e246720c4835
  69:     0x7fbf7ae82d5e - rustc::util::common::time::h0ca0fd77a3a38e7f
  70:     0x7fbf7b058a9f - rustc_typeck::check_crate::h6efa337673fd0bf9
  71:     0x7fbf7a9573da - rustc_interface::passes::analysis::h5ca1dcf5c3fa00a4
  72:     0x7fbf7a862481 - rustc::ty::query::__query_compute::analysis::hb2ca05cf73df93a7
  73:     0x7fbf7a845759 - rustc::dep_graph::graph::DepGraph::with_task_impl::hada062624bcc756b
  74:     0x7fbf7a859c5e - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query::hfa3b77f4283d964e
  75:     0x7fbf7a8767aa - rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}::h2cccf239a8fcfaff
  76:     0x7fbf7a9d3b0a - rustc_interface::passes::create_global_ctxt::{{closure}}::h411ea04f079efa05
  77:     0x7fbf7a87926e - rustc_interface::interface::run_compiler_in_existing_thread_pool::h495ac89e699120f3
  78:     0x7fbf7a888522 - std::thread::local::LocalKey<T>::with::h2b6e98dea32965c7
  79:     0x7fbf7a89c21e - scoped_tls::ScopedKey<T>::set::h5242c74f962b8d66
  80:     0x7fbf7a8d1482 - syntax::with_globals::h36bb832d23aa0930
  81:     0x7fbf7a83f940 - std::sys_common::backtrace::__rust_begin_short_backtrace::h5ac2bb0fb1bde18d
  82:     0x7fbf7a3817fa - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:80
  83:     0x7fbf7a864619 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h999a457b750ab865
  84:     0x7fbf7a3543ff - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h8937f8752182f20d
                               at /rustc/4295eea903a9e1014ee30f82930f5ec08d888077/src/liballoc/boxed.rs:922
  85:     0x7fbf7a3804a0 - <alloc::boxed::Box<F> as core::ops::function::FnOnce<A>>::call_once::h2cc60d9264e9fe0a
                               at /rustc/4295eea903a9e1014ee30f82930f5ec08d888077/src/liballoc/boxed.rs:922
  86:     0x7fbf7a3804a0 - std::sys_common::thread::start_thread::h7aa97315f70bdaea
                               at src/libstd/sys_common/thread.rs:13
  87:     0x7fbf7a3804a0 - std::sys::unix::thread::Thread::new::thread_start::h15d5599c4b4a4cef
                               at src/libstd/sys/unix/thread.rs:79
  88:     0x7fbf7a28957f - start_thread
  89:     0x7fbf7a19c0e3 - __clone
  90:                0x0 - <unknown>
query stack during panic:
#0 [const_eval_raw] const-evaluating `uperms::{{constant}}#1`
#1 [const_eval] const-evaluating + checking `uperms::{{constant}}#1`
#2 [const_eval] const-evaluating + checking `uperms::{{constant}}#1`
#3 [typeck_tables_of] processing `uperms`
#4 [typeck_item_bodies] type-checking all item bodies
#5 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error


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.39.0-nightly (4295eea90 2019-08-30) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile `farklemaster`.

To learn more, run the command again with --verbose.
@goddessfreya
Copy link
Contributor Author

goddessfreya commented Aug 31, 2019

Even smaller example:

#![feature(const_generics)]

fn uperms<const DICE_NUM: usize>() -> Vec<[u8; DICE_NUM]> {
    if DICE_NUM <= 1 {
        panic!();
    } else {
        let pperms = uperms::<{ DICE_NUM - 1 }>();
        panic!();
    }
}

fn main() {
    let perms1 = uperms::<{ 1 }>();
}

And the smallest of course:

#![feature(const_generics)]

fn uperms<const DICE_NUM: usize>() -> Vec<[u8; DICE_NUM]> {
    let pperms = uperms::<{ DICE_NUM - 1 }>();
}

fn main() {
    let perms1 = uperms::<{ 1 }>();
}

@goddessfreya goddessfreya changed the title Recursive const generic array of decreasing length causes ICE. Recursive fn that requires const generic array of decreasing length causes ICE. Aug 31, 2019
@hellow554
Copy link
Contributor

This isn't bound to subtraction or number literals, but to every modification to the generic parameter, e.g.

#![feature(const_generics)]

pub fn uperms<const DICE_NUM: usize, const BAR: usize>() {
    uperms::<{ DICE_NUM + BAR }, { BAR }>();
}

fn main() {}

@goddessfreya goddessfreya changed the title Recursive fn that requires const generic array of decreasing length causes ICE. Recursive fn with varying const generic parameter causes ICE. Sep 2, 2019
@goddessfreya
Copy link
Contributor Author

Looks to be a dupe of #58987. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants