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

Internal compiler error on implementation with 'complex' constant trait bounds #86953

Closed
cs-t1 opened this issue Jul 7, 2021 · 2 comments · Fixed by #88166
Closed

Internal compiler error on implementation with 'complex' constant trait bounds #86953

cs-t1 opened this issue Jul 7, 2021 · 2 comments · Fixed by #88166
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@cs-t1
Copy link

cs-t1 commented Jul 7, 2021

Code

The code fragment is located here : code

I narrowed down the error to the following block :

Code fragment

impl<const N: usize, const M: usize> Add<&StackBitSet<M>> for StackBitSet<N>
where
    [(); usize_count(N)]: Sized,
    [(); usize_count(M)]: Sized,
    [(); usize_count(const_min(N, M))]: Sized,
{
    type Output = StackBitSet<{ const_min(N, M) }>;

    fn add(self, other: &StackBitSet<M>) -> StackBitSet<{ const_min(N, M) }> {
        self.union(other)
    }
}

Context

I am experimenting with a naive implementation of bitsets, relying heavily on some (as I discovered) unstable features : const_evaluatable_checked and const_generics. My implementation of the Add trait is probably terribly wrong!

NB: I only get the error with the Debug preset. When building on the Release preset I don't get any error.

Meta

I only provide the data for the nightly compiler, as unstable features are not enabled on the release version.

rustc --version --verbose:

rustc 1.55.0-nightly (952fdf2a1 2021-07-05)
binary: rustc
commit-hash: 952fdf2a1119affa1b37bcacb0c49cf9f0168ac8
commit-date: 2021-07-05
host: x86_64-unknown-linux-gnu
release: 1.55.0-nightly
LLVM version: 12.0.1

Error output

error: internal compiler error: compiler/rustc_middle/src/ich/impls_ty.rs:94:17: StableHasher: unexpected region '_#1r

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1006:9
Backtrace

stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_middle::ich::impls_ty::<impl rustc_data_structures::stable_hasher::HashStable<rustc_middle::ich::hcx::StableHashingContext> for rustc_middle::ty::sty::RegionKind>::hash_stable
   8: std::thread::local::LocalKey<T>::with
   9: rustc_query_system::dep_graph::dep_node::DepNode<K>::construct
  10: rustc_query_system::query::plumbing::get_query_impl
  11: rustc_query_system::query::plumbing::get_query
  12: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::try_unify_abstract_consts
  13: rustc_trait_selection::traits::fulfill::FulfillProcessor::progress_changed_obligations
  14: rustc_data_structures::obligation_forest::ObligationForest<O>::process_obligations
  15: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_where_possible
  16: <rustc_trait_selection::traits::fulfill::FulfillmentContext as rustc_infer::traits::engine::TraitEngine>::select_all_or_error
  17: rustc_infer::infer::InferCtxtBuilder::enter
  18: rustc_typeck::check::compare_method::compare_impl_method
  19: rustc_typeck::check::check::check_item_type
  20: rustc_middle::hir::map::Map::visit_item_likes_in_module
  21: rustc_typeck::check::check::check_mod_item_types
  22: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  23: rustc_data_structures::stack::ensure_sufficient_stack
  24: rustc_query_system::query::plumbing::force_query_with_job
  25: rustc_query_system::query::plumbing::get_query_impl
  26: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  27: rustc_session::utils::<impl rustc_session::session::Session>::time
  28: rustc_typeck::check_crate
  29: rustc_interface::passes::analysis
  30: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_eval_always_task
  33: rustc_data_structures::stack::ensure_sufficient_stack
  34: rustc_query_system::query::plumbing::force_query_with_job
  35: rustc_query_system::query::plumbing::get_query_impl
  36: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  37: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  38: rustc_span::with_source_map
  39: rustc_interface::interface::create_compiler_and_run
  40: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@cs-t1 cs-t1 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 Jul 7, 2021
@jonas-schievink jonas-schievink added F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` labels Jul 7, 2021
@syvb
Copy link
Contributor

syvb commented Jul 7, 2021

Here's a minimized example:

#![feature(const_generics)]
#![feature(const_evaluatable_checked)]

use std::ops::Add;

pub struct StackBitSet<const N: usize> where [(); 0]: Sized;

impl<const N: usize, const M: usize> Add<&StackBitSet<M>> for StackBitSet<N>
where
    [(); 0+0]: Sized, // changing 0+0 to 0 makes this work
    [(); 0]: Sized,
    [(); 0]: Sized,
{
    type Output = StackBitSet<0>;
    fn add(self, _: &StackBitSet<M>) -> Self::Output {
        loop {}
    }
}

#[test]
fn bitset_create() {
    let _a: StackBitSet<42> = StackBitSet;
}

playground

This seems like a duplicate of #79251.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Aug 12, 2021
@BoxyUwU BoxyUwU added the A-const-generics Area: const generics (parameters and arguments) label Aug 18, 2021
@BoxyUwU
Copy link
Member

BoxyUwU commented Aug 18, 2021

#![feature(const_generics, const_evaluatable_checked)]
#![allow(incomplete_features)]

struct Foo;
impl<'a> std::ops::Add<&'a Foo> for Foo
where
    [(); 0 + 0]: Sized,
{
    type Output = ();
    fn add(self, _: &Foo) -> Self::Output {
        loop {}
    }
}

smallerer repro

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) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.

5 participants