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: eval_const_to_op: Unexpected ConstKind #74634

Closed
steffahn opened this issue Jul 22, 2020 · 4 comments · Fixed by #76581
Closed

ICE: eval_const_to_op: Unexpected ConstKind #74634

steffahn opened this issue Jul 22, 2020 · 4 comments · Fixed by #76581
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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

@steffahn
Copy link
Member

steffahn commented Jul 22, 2020

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

trait If<const COND: bool> {}
impl If<true> for () {}

trait IsZero<const N: u8> {
    type Answer;
}

struct True;
struct False;

impl<const N: u8> IsZero<N> for ()
where (): If<{N == 0}> {
    type Answer = True;
}

trait Foobar<const N: u8> {}

impl<const N: u8> Foobar<N> for ()
where (): IsZero<N, Answer = True> {}

impl<const N: u8> Foobar<N> for ()
where (): IsZero<N, Answer = False> {}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: src/librustc_mir/interpret/operand.rs:569:17: eval_const_to_op: Unexpected ConstKind Const { ty: u8, val: Bound(DebruijnIndex(0), 0) }
  --> src/lib.rs:15:15
   |
15 | where (): If<{N == 0}> {
   |               ^^^^^^

thread 'rustc' panicked at 'Box<Any>', /rustc/f9a3086363f214f2b56bef30f0ac572e1a9127f1/src/libstd/macros.rs:13:23
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.47.0-nightly (f9a308636 2020-07-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 --crate-type lib

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

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

Probably related: #72819

Removing (at least) one of the impls for Foobar makes the panic go away, and the compiler correctly reports the error:

   Compiling playground v0.0.1 (/playground)
error: constant expression depends on a generic parameter
  --> src/lib.rs:15:11
   |
15 | where (): If<{N == 0}> {
   |           ^^^^^^^^^^^^
   |
   = note: this may fail depending on what value the parameter takes

error: aborting due to previous error

error: could not compile `playground`.

To learn more, run the command again with --verbose.

@rustbot modify labels: I-ICE, T-compiler, A-const-eval, A-const-generics, C-bug, F-const_generics, requires-nightly

@rustbot rustbot added A-const-eval Area: Constant evaluation (MIR interpretation) A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. 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. F-const_generics `#![feature(const_generics)]` labels Jul 22, 2020
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 24, 2020
@RalfJung
Copy link
Member

That's happening here:

span_bug!(self.cur_span(), "const_to_op: Unexpected ConstKind {:?}", val)

I don#t think there is a meaningful way to evaluate a polymorphic constant, so either some code earlier screwed up to even get so far, or we need to throw TooGeneric here.

Cc @oli-obk @eddyb

@oli-obk
Copy link
Contributor

oli-obk commented Jul 29, 2020

cc @lcnr

This ICE is totally expected. Using features that emit the incomplete_features lint are expected to ICE, otherwise they would not emit said lint. The const evaluator is not at fault here, there's just no way to evaluate this.

@lcnr
Copy link
Contributor

lcnr commented Jul 29, 2020

hmm, we shouldn't try to evaluate this constant here or at least have it be a ty::Param instead of a ty::Placeholder.

Not quite sure what's going on here, will have to look at it in more detail soon

@lcnr
Copy link
Contributor

lcnr commented Aug 4, 2020

So we probably fail here because we call const_eval_resolve with a ConstKind::Infer which get's canonicalized to a ConstKind::Bound.

All of that seems correct to me 🤔 Is it possible that we should treat ConstKind::Bound similar to ConstKind::Param and "just" return TooGeneric here?

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 19, 2020
do not ICE on bound variables, return `TooGeneric` instead

fixes rust-lang#73260, fixes rust-lang#74634, fixes rust-lang#76595

r? @nikomatsakis
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 21, 2020
do not ICE on bound variables, return `TooGeneric` instead

fixes rust-lang#73260, fixes rust-lang#74634, fixes rust-lang#76595

r? @nikomatsakis
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 21, 2020
do not ICE on bound variables, return `TooGeneric` instead

fixes rust-lang#73260, fixes rust-lang#74634, fixes rust-lang#76595

r? @nikomatsakis
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Sep 22, 2020
do not ICE on bound variables, return `TooGeneric` instead

fixes rust-lang#73260, fixes rust-lang#74634, fixes rust-lang#76595

r? @nikomatsakis
ecstatic-morse added a commit to ecstatic-morse/rust that referenced this issue Sep 22, 2020
do not ICE on bound variables, return `TooGeneric` instead

fixes rust-lang#73260, fixes rust-lang#74634, fixes rust-lang#76595

r? @nikomatsakis
@bors bors closed this as completed in 30f1bab Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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.

6 participants