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

failed to lift QueryResponse when passing only a const generic and not a type generic #61516

Closed
shepmaster opened this issue Jun 4, 2019 · 9 comments · Fixed by #65652
Closed
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. F-const_generics `#![feature(const_generics)]` 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

@shepmaster
Copy link
Member

#![feature(const_generics)]

struct FakeArray<T, const N: usize>(T);

impl<T, const N: usize> FakeArray<T, { N }> {
    fn len(&self) -> usize {
        N
    }
}

fn main() {
    let fa = FakeArray::<{ 32 }>(1);
    println!("{}", fa.len());
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
 --> src/main.rs:1:12
  |
1 | #![feature(const_generics)]
  |            ^^^^^^^^^^^^^^

error: internal compiler error: src/librustc/infer/canonical/canonicalizer.rs:553: failed to lift `QueryResponse { var_values: CanonicalVarValues { var_values: [^0, Const { ty: _, val: Infer(Canonical(DebruijnIndex(0), 1)) }] }, region_constraints: [], certainty: Proven, value: FakeArray<^0, _: _> }`, canonicalized from `QueryResponse { var_values: CanonicalVarValues { var_values: [{integer}, Const { ty: _, val: Infer(Var(_#0c)) }] }, region_constraints: [], certainty: Proven, value: FakeArray<{integer}, _: _> }`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error


note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.37.0-nightly (6ffb8f53e 2019-06-03) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

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

error: Could not compile `playground`.

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

@shepmaster shepmaster added C-bug Category: This is a bug. A-const-generics Area: const generics (parameters and arguments) labels Jun 4, 2019
@shepmaster
Copy link
Member Author

/cc @yodaldevoid @varkor

Related to but different from #60879

@shepmaster
Copy link
Member Author

This can be avoided by expressly allowing the type to be inferred: let fa = FakeArray::<_, { 32 }>(1);

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 4, 2019
@Centril Centril added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Jun 4, 2019
@varkor
Copy link
Member

varkor commented Jun 4, 2019

@yodaldevoid on Zulip:

Ah, I see what is triggering it. Your code has an explicit const param in the initializer while there code infers it

(as compared to #60879)

@varkor
Copy link
Member

varkor commented Jun 6, 2019

After #61570, this isn't fixed, but commenting out the .len() call will cause it to error without ICEing (at the moment, it ICEs even without that line).

@qwerty19106
Copy link

I configure struct by complicated const value and get this ICE.
My code does something like this:

#![feature(const_generics)]

struct Config(usize);
const CONFIG: Config = Config(5);

struct FakeArray<T, const N: Config>(T);

impl<T, const N: Config> FakeArray<T, { N }> {
    const fn new(val: T) -> Self {
        Self(val)
    }
}

fn main() {
    let fa = FakeArray::new::<_, { CONFIG }>(1);
}

Error:

internal compiler error: src/librustc/infer/canonical/canonicalizer.rs:557: failed to lift `QueryResponse { var_values: CanonicalVarValues { var_values: [^0, Const { ty: _, val: Infer(Canonical(DebruijnIndex(0), 1)) }] }, region_constraints: [], certainty: Proven, value: FakeArray<^0, _: _> }`, canonicalized from `QueryResponse { var_values: CanonicalVarValues { var_values: [_, Const { ty: _, val: Infer(Var(_#1c)) }] }, region_constraints: [], certainty: Proven, value: FakeArray<_, _: _> }

Note that type erase (as proposed @shepmaster) does not help in my case. Until I found a way around this ICE.

@burrbull
Copy link
Contributor

Same error on:

#![feature(const_generics)]

pub struct Array<const N: usize> {
    buffer: [i32; N],
}

impl<const N: usize> Array<{N}> {
    pub fn new() -> Self {
        Self {
            buffer: [0i32; N],
        }
    }
}

fn main () {
    let v: Array<5> = Array::new();
}

@burrbull
Copy link
Contributor

I tried to port @japaric 's heapless from GenericArray to const generics in this branch. Some of code is commented because of this bug and several other. I think this is good test for const generics

@Centril Centril added requires-nightly This issue requires a nightly compiler in some way. F-const_generics `#![feature(const_generics)]` labels Aug 6, 2019
@JohnTitor
Copy link
Member

Cannot reproduce the ICE with the above playground link.

@yodaldevoid
Copy link
Contributor

It should be noted that while this no longer ICEs, this is because rustc no longer attempts to infer the type parameter causing it to fail to compile.

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)]` 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.

8 participants