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: feature(generic_const_exprs) enabled in one crate but not another #79018

Closed
jplatte opened this issue Nov 13, 2020 · 10 comments
Closed

ICE: feature(generic_const_exprs) enabled in one crate but not another #79018

jplatte opened this issue Nov 13, 2020 · 10 comments
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-generic_const_exprs `#![feature(generic_const_exprs)]` 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

@jplatte
Copy link
Contributor

jplatte commented Nov 13, 2020

Extracted out from #78139 (comment), as that issue was closed but my case still ICEs

Given this code:

src/lib.rs:

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

pub struct Const<const U: u8>;

pub trait Trait {
    type AssocTy;
    fn assoc_fn() -> Self::AssocTy;
}

impl<const U: u8> Trait for Const<U>
where
    Const<{ my_const_fn(U) }>: ,
{
    type AssocTy = Const<{ my_const_fn(U) }>;
    fn assoc_fn() -> Self::AssocTy {
        Const
    }
}

const fn my_const_fn(val: u8) -> u8 {
    // body of this function doesn't matter
    val
}

examples/breakit.rs:

use my_crate::{Const, Trait};

fn main() {
    let _ = Const::<1>::assoc_fn();
}

I get the following error:

error: constant expression depends on a generic parameter
  |
  = note: this may fail depending on what value the parameter takes

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:37:32: could not fully normalize `<my_crate::Const<U> as my_crate::Trait>::AssocTy`
Backtrace
thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:945: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_infer::infer::InferCtxtBuilder::enter
   9: rustc_traits::normalize_erasing_regions::normalize_generic_arg_after_erasing_regions
  10: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  11: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  12: rustc_data_structures::stack::ensure_sufficient_stack
  13: rustc_query_system::query::plumbing::get_query_impl
  14: rustc_middle::ty::structural_impls::fold_list
  15: rustc_middle::ty::normalize_erasing_regions::<impl rustc_middle::ty::context::TyCtxt>::normalize_erasing_regions
  16: rustc_middle::ty::layout::<impl rustc_middle::ty::instance::Instance>::fn_sig_for_fn_abi
  17: <rustc_target::abi::call::FnAbi<&rustc_middle::ty::TyS> as rustc_middle::ty::layout::FnAbiExt<C>>::of_instance
  18: rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_call_terminator
  19: rustc_codegen_ssa::mir::block::<impl rustc_codegen_ssa::mir::FunctionCx<Bx>>::codegen_block
  20: rustc_codegen_ssa::mir::codegen_mir
  21: rustc_codegen_ssa::base::codegen_instance
  22: <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define
  23: rustc_codegen_llvm::base::compile_codegen_unit::module_codegen
  24: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  25: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task
  26: rustc_codegen_llvm::base::compile_codegen_unit
  27: rustc_codegen_ssa::base::codegen_crate
  28: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  29: rustc_session::utils::<impl rustc_session::session::Session>::time
  30: rustc_interface::queries::Queries::ongoing_codegen
  31: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  32: rustc_span::with_source_map
  33: 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.49.0-nightly (e3051d8c2 2020-10-16) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<my_crate::Const<U> as my_crate::Trait>::AssocTy`
end of query stack
error: aborting due to 2 previous errors

error: could not compile `my_crate`

It goes away when putting all of the code into one compilation unit.

@jyn514 jyn514 added A-const-generics Area: const generics (parameters and arguments) F-generic_const_exprs `#![feature(generic_const_exprs)]` 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. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ C-bug Category: This is a bug. labels Nov 13, 2020
@in42
Copy link
Contributor

in42 commented Nov 15, 2020

@lcnr Hi, I would like to work on this. Which files should I look at to get started?

@lcnr lcnr added the E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. label Nov 15, 2020
@lcnr

This comment was marked as off-topic.

@jplatte

This comment was marked as off-topic.

@lcnr

This comment was marked as off-topic.

@lcnr
Copy link
Contributor

lcnr commented Nov 15, 2020

:/

closing this as somewhat intended.

const_evaluatable_checked has to be active in both the crate defining the generic const operation and in the crate which tries to use it.

I don't think there is much we can do here. This compiles if you change example/breakit.rs to the following

#![feature(const_evaluatable_checked)]

use what::{Const, Trait};

fn main() {
    let _ = Const::<1>::assoc_fn();
}

@lcnr lcnr closed this as completed Nov 15, 2020
@jplatte
Copy link
Contributor Author

jplatte commented Nov 15, 2020

Ohh, of course. But surely this could produce an error instead of an ICE, no?

@lcnr
Copy link
Contributor

lcnr commented Nov 16, 2020

This could, I don't know how to do that though 🤔

so yeah, let's keep that open for now

@lcnr lcnr reopened this Nov 16, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Nov 16, 2020

This is almost impossible to emit a real error about. What we can do is add more text to the ICE

fanninpm added a commit to fanninpm/glacier that referenced this issue Dec 17, 2020
fanninpm added a commit to fanninpm/glacier that referenced this issue Dec 19, 2020
@chengniansun

This comment has been minimized.

@BoxyUwU BoxyUwU changed the title ICE: Could not fully normalize type with feature(const_evaluatable_checked) ICE: feature(const_evaluatable_checked) enabled in one crate but not another Aug 19, 2021
@BoxyUwU BoxyUwU changed the title ICE: feature(const_evaluatable_checked) enabled in one crate but not another ICE: feature(generic_const_exprs) enabled in one crate but not another Sep 15, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this issue Mar 10, 2022
Better error for normalization errors from parent crates that use `#![feature(generic_const_exprs)]`

This PR implements a somewhat rudimentary heuristic to suggest using `#![feature(generic_const_exprs)]` in a child crate when a function from a foreign crate (that may have used `#![feature(generic_const_exprs)]`) fails to normalize during codegen.

cc: rust-lang#79018
cc: rust-lang#94287
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Mar 10, 2022
Better error for normalization errors from parent crates that use `#![feature(generic_const_exprs)]`

This PR implements a somewhat rudimentary heuristic to suggest using `#![feature(generic_const_exprs)]` in a child crate when a function from a foreign crate (that may have used `#![feature(generic_const_exprs)]`) fails to normalize during codegen.

cc: rust-lang#79018
cc: rust-lang#94287
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 10, 2022
Better error for normalization errors from parent crates that use `#![feature(generic_const_exprs)]`

This PR implements a somewhat rudimentary heuristic to suggest using `#![feature(generic_const_exprs)]` in a child crate when a function from a foreign crate (that may have used `#![feature(generic_const_exprs)]`) fails to normalize during codegen.

cc: rust-lang#79018
cc: rust-lang#94287
@lcnr lcnr added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. E-medium Call for participation: Medium difficulty. Experience needed to fix: Intermediate. labels Mar 21, 2022
@lcnr
Copy link
Contributor

lcnr commented Mar 21, 2022

the ICE has been fixed in #94440 so I am going to close this issue. Don't think we need any additional tests for that PR.

@lcnr lcnr closed this as completed Mar 21, 2022
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-generic_const_exprs `#![feature(generic_const_exprs)]` 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

No branches or pull requests

6 participants