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_evaluatable_checked and lifetime parameter #85031

Closed
Johannesd3 opened this issue May 7, 2021 · 3 comments · Fixed by #88166
Closed

ICE with const_evaluatable_checked and lifetime parameter #85031

Johannesd3 opened this issue May 7, 2021 · 3 comments · Fixed by #88166
Labels
A-const-generics Area: const generics (parameters and arguments) A-incr-comp Area: Incremental compilation 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) ❄️ 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

@Johannesd3
Copy link

Code

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

pub struct Ref<'a, const NUM: usize>(&'a i32);

impl<'a, const NUM: usize> Ref<'a, NUM> {
    pub fn foo<const A: usize>(r: Ref<'a, A>) -> Self
    where
        ([(); NUM - A], [(); A - NUM]): Sized,
    {
        Self::bar(r)
    }

    pub fn bar<const A: usize>(r: Ref<'a, A>) -> Self
    where
        ([(); NUM - A], [(); A - NUM]): Sized,
    {
        Self(r.0)
    }
}

Meta

rustc --version --verbose:

rustc 1.54.0-nightly (676ee1472 2021-05-06)
binary: rustc
commit-hash: 676ee14729462585b969bbc52f32c307403f4126
commit-date: 2021-05-06
host: x86_64-unknown-linux-gnu
release: 1.54.0-nightly
LLVM version: 12.0.0

Error output

note: run with `RUST_BACKTRACE=1` environment variable to display a 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.54.0-nightly (676ee1472 2021-05-06) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib

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

query stack during panic:
#0 [typeck] type-checking `<impl at src/lib.rs:6:1: 20:2>::foo`
#1 [typeck_item_bodies] type-checking all item bodies
end of query stack
error: aborting due to previous error

error: could not compile `ice-minimal`

To learn more, run the command again with --verbose.
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_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::resolve_vars_with_obligations
  17: rustc_typeck::check::fn_ctxt::_impl::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::structurally_resolved_type
  18: rustc_typeck::check::callee::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  19: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  20: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  21: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  22: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  23: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  24: rustc_typeck::check::check::check_fn
  25: rustc_typeck::check::inherited::InheritedBuilder::enter
  26: rustc_typeck::check::typeck
  27: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  28: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  29: rustc_data_structures::stack::ensure_sufficient_stack
  30: rustc_query_system::query::plumbing::force_query_with_job
  31: rustc_query_system::query::plumbing::get_query_impl
  32: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  33: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  34: rustc_typeck::check::typeck_item_bodies
  35: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  37: rustc_data_structures::stack::ensure_sufficient_stack
  38: rustc_query_system::query::plumbing::force_query_with_job
  39: rustc_query_system::query::plumbing::get_query_impl
  40: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  41: rustc_session::utils::<impl rustc_session::session::Session>::time
  42: rustc_typeck::check_crate
  43: rustc_interface::passes::analysis
  44: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  45: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  46: rustc_data_structures::stack::ensure_sufficient_stack
  47: rustc_query_system::query::plumbing::force_query_with_job
  48: rustc_query_system::query::plumbing::get_query_impl
  49: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  50: rustc_interface::passes::QueryContext::enter
  51: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  52: rustc_span::with_source_map
  53: rustc_interface::interface::create_compiler_and_run
  54: scoped_tls::ScopedKey<T>::set

@Johannesd3 Johannesd3 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 May 7, 2021
@Johannesd3
Copy link
Author

Johannesd3 commented May 7, 2021

Here's another, slightly more minimal example:

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

pub struct Ref<'a>(&'a i32);

impl<'a> Ref<'a> {
    pub fn foo<const A: usize, const B: usize>()
    where
        ([(); A - B], [(); A - B]): Sized,
    {
        Self::bar::<A, B>()
    }

    pub fn bar<const A: usize, const B: usize>()
    where
        ([(); A - B], [(); A - B]): Sized,
    {
    }
}

I also noticed it doesn't occur with CARGO_INCREMENTAL=0 set (but it also occurs on clean builds)

EDIT: Another example:

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

pub struct Ref<'a>(&'a i32);

impl<'a> Ref<'a> {
    pub fn foo<const A: usize>()
    where
        ([(); A - 0], ()): Sized,
    {
        Self::foo::<A>()
    }
}

If I should guess, this ICE occurs if a function

  • which is contained in an impl block with lifetime parameter
  • and has a where clause with complicated type that requires const_evaluatable_checked

calls a function with the same type in its where clause.

Edit 2: Yet another

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

pub struct Ref<'a>(&'a i32);

impl<'a> Ref<'a> {
    pub fn foo<const A: usize>() -> [(); A - 0] {
        Self::foo()
    }
}

In this case, it ICEs even with a simple array type.

@Johannesd3
Copy link
Author

@rustbot modify labels: +A-incr-comp +A-const-generics +F-const_evaluatable_checked +F-const_generics +requires-nightly

Could be related to #77708

@rustbot rustbot added A-const-generics Area: const generics (parameters and arguments) A-incr-comp Area: Incremental compilation F-generic_const_exprs `#![feature(generic_const_exprs)]` F-const_generics `#![feature(const_generics)]` requires-nightly This issue requires a nightly compiler in some way. labels May 7, 2021
Johannesd3 added a commit to Johannesd3/glacier that referenced this issue May 8, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label May 8, 2021
@0x5459
Copy link

0x5459 commented May 17, 2021

Similar problem:

#![feature(const_generics, const_evaluatable_checked)]


fn test<const SIZE: usize>() {}

trait SomeTrait {
    const SIZE: usize;
}

struct A<'a, T> {
    some_ref: &'a str,
    _maker: core::marker::PhantomData<T>,
}

impl<'a, T: SomeTrait> A<'a, T>
where [(); T::SIZE]: ,
{
    fn call_test() {
        test::<{ T::SIZE }>();
    }
}

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-incr-comp Area: Incremental compilation 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) ❄️ 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.

4 participants