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 min_const_generics and mir-opt-level=2 #79269

Closed
leonardo-m opened this issue Nov 21, 2020 · 0 comments · Fixed by #79272
Closed

[ICE] with min_const_generics and mir-opt-level=2 #79269

leonardo-m opened this issue Nov 21, 2020 · 0 comments · Fixed by #79272
Labels
A-const-generics Area: const generics (parameters and arguments) A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. 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

@leonardo-m
Copy link

#![feature(min_const_generics)]
#[derive(Clone)]
struct Foo<TK, TV, const LEN: usize> {
    data: [(TK, TV); LEN],
    len: usize,
}
impl<TK: PartialEq, TV, const LEN: usize> Foo<TK, TV, LEN> {
    fn insert(&mut self, k: TK, v: TV) {
        if let Some((_, v0)) = self.data[.. self.len].iter_mut().find(|(k0, _)| k == *k0) {
            *v0 = v;
        } else {
            self.data[self.len] = (k, v);
            self.len += 1;
        }
    }
}
fn main() {
    let mut z = Vec::<Foo<u32, u32, 10>>::new();
    while let Some(x) = z.pop() {
        let mut y = x.clone();
        y.insert(0, 1);
    }
}

Gives:

error: internal compiler error: /rustc/593fe977a77ad5a7aec23c6cb0f86a3470221670\compiler\rustc_middle\src\ty\consts.rs:201:32: expected usize, got Const {
    ty: usize,
    val: Param(
        LEN/#2,
    ),
}

thread 'rustc' panicked at 'Box<Any>', compiler\rustc_errors\src\lib.rs:958:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_middle::ty::consts::Const::eval_usize::{{closure}}
   9: rustc_mir::shim::make_shim
  10: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_shims>::compute
  11: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  12: rustc_data_structures::stack::ensure_sufficient_stack
  13: rustc_query_system::query::plumbing::get_query_impl
  14: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir
  15: rustc_mir::transform::inline::Inliner::process_blocks
  16: <rustc_mir::transform::inline::Inline as rustc_mir::transform::MirPass>::run_pass
  17: rustc_mir::transform::run_passes
  18: rustc_mir::transform::run_optimization_passes
  19: rustc_mir::transform::optimized_mir
  20: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  21: rustc_data_structures::stack::ensure_sufficient_stack
  22: rustc_query_system::query::plumbing::get_query_impl
  23: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir
  24: rustc_mir::transform::inline::Inliner::process_blocks
  25: <rustc_mir::transform::inline::Inline as rustc_mir::transform::MirPass>::run_pass
  26: rustc_mir::transform::run_passes
  27: rustc_mir::transform::run_optimization_passes
  28: rustc_mir::transform::optimized_mir
  29: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  30: rustc_data_structures::stack::ensure_sufficient_stack
  31: rustc_query_system::query::plumbing::get_query_impl
  32: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::instance_mir
  33: rustc_mir::monomorphize::collector::collect_neighbours
  34: rustc_mir::monomorphize::collector::collect_items_rec
  35: rustc_session::utils::<impl rustc_session::session::Session>::time
  36: rustc_mir::monomorphize::collector::collect_crate_mono_items
  37: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  38: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::collect_and_partition_mono_items>::compute
  39: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  40: rustc_data_structures::stack::ensure_sufficient_stack
  41: rustc_query_system::query::plumbing::get_query_impl
  42: rustc_codegen_ssa::base::codegen_crate
  43: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  44: rustc_interface::passes::QueryContext::enter
  45: rustc_interface::queries::Queries::ongoing_codegen
  46: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  47: rustc_span::with_source_map
  48: scoped_tls::ScopedKey<T>::set
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.50.0-nightly (593fe977a 2020-11-20) running on x86_64-pc-windows-gnu

note: compiler flags: -Z mir-opt-level=2 -C lto

query stack during panic:
#0 [mir_shims] generating MIR shim for `std::clone::Clone::clone`
#1 [optimized_mir] optimizing MIR for `<Foo<TK, TV, LEN> as std::clone::Clone>::clone`
#2 [optimized_mir] optimizing MIR for `main`
#3 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error
@leonardo-m leonardo-m added the C-bug Category: This is a bug. label Nov 21, 2020
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining F-min_const_generics T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. requires-nightly This issue requires a nightly compiler in some way. labels Nov 21, 2020
@bors bors closed this as completed in 68c9caa Nov 21, 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-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining C-bug Category: This is a bug. 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.

2 participants