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

error: internal compiler error: "inference variables in ..." on packed type #61402

Closed
zao opened this issue May 31, 2019 · 7 comments · Fixed by #62240
Closed

error: internal compiler error: "inference variables in ..." on packed type #61402

zao opened this issue May 31, 2019 · 7 comments · Fixed by #62240
Assignees
Labels
A-inference Area: Type inference C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zao
Copy link

zao commented May 31, 2019

Given the following source code in both release 1.35.0 and 1.36.0-nightly (e305df184 2019-04-24), I encounter an internal compiler error using nalgebra 0.18.0.

The code is probably not legal to begin with as I ran into it as I was moving from my own homebrewn math code to nalgebra. I have the impression that the compiler probably shouldn't ICE regardless of what junk you feed it, so I'm still reporting this.

use nalgebra::Vector3;

#[derive(Debug, Clone, Copy)]
#[repr(C, packed)]
struct Vertex {
    pos: Vector3<f32>,
    clr: Vector3<f32>,
}

Build output from cargo +nightly build:

   Compiling nalgebra v0.18.0
   Compiling nalgebra-repro v0.1.0 (F:\Temp\nalgebra-repro)
error: internal compiler error: inference variables in nalgebra::base::matrix::Matrix<f32, nalgebra::base::dimension::U3, nalgebra::base::dimension::U1, nalgebra::base::array_storage::ArrayStorage<_, _, _>>
 --> src\lib.rs:5:1
  |
5 | / struct Vertex {
6 | |     pos: Vector3<f32>,
7 | |     clr: Vector3<f32>,
8 | | }
  | |_^

thread 'rustc' panicked at 'no errors encountered even though `delay_span_bug` issued', src\librustc_errors\lib.rs:355:17
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

error: internal compiler error: unexpected panic

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.36.0-nightly (e305df184 2019-04-24) running on x86_64-pc-windows-msvc

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

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

error: Could not compile `nalgebra-repro`.

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

I unfortunately do not have a newer nightly to test with due to the lack of a more recent RLS blocking the rustup attempt.

@Centril Centril added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-nominated A-inference Area: Type inference T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 31, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label May 31, 2019
@HeroicKatora
Copy link
Contributor

Still encountering this in rustc 1.37.0-nightly (03ee55bb1 2019-06-01).

Indepent of the issue, you can install specific compiler versions with necessary components according to this matrix and this installation process.

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2019

This ICE itself arises from this line:

item.span, &format!("inference variables in {:?}", ty));

@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2019

triage: P-high, assigning to self. Removing nomination.

@pnkfelix pnkfelix added the P-high High priority label Jun 6, 2019
@pnkfelix pnkfelix self-assigned this Jun 6, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jun 11, 2019

Okay I've narrowed the test case down

click for first reduction

Here is a standalone file (play):

#![allow(unused_imports, dead_code)]

pub struct U1;

pub trait ArrayLength {  }
impl ArrayLength for U1 { }

pub trait Trait { type Output; }
impl Trait for U1 { type Output = U1; }

pub trait DimName { type Value; }
impl DimName for U1 { type Value = U1; }

pub struct ArrayStorage<R>
where
    R: DimName,
    R::Value: Trait,
    <R::Value as Trait>::Output: ArrayLength,
{
    data: <R::Value as Trait>::Output,
}

pub struct DefaultAllocator;

pub trait Allocator<R = U1> { type Buffer; }
impl<R: DimName> Allocator<R> for DefaultAllocator
where
    R::Value: Trait,
    <R::Value as Trait>::Output: ArrayLength,
{
    type Buffer = ArrayStorage<R>;
}

#[repr(C, packed)]
struct Vertex {
    pos: <DefaultAllocator as Allocator>::Buffer
}

fn main() { println!("Hello, world!"); }

Update: Got a better reduction now (play):

#![allow(unused_imports, dead_code)]

pub struct S;

pub trait Trait<R> { type Assoc; }

impl<X> Trait<X> for S { type Assoc = X; }

#[repr(C, packed)]
struct Packed {
    pos: Box<<S as Trait<usize>>::Assoc>,
}

fn main() { println!("Hello, world!"); }

@pnkfelix
Copy link
Member

This is a stable-to-stable regression, injected between rust 1.23 and 1.24.

@pnkfelix pnkfelix added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jun 11, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jun 11, 2019

the fact that the bug goes away if you take away the packed on struct Vertex leads me to hypothesize that the bug is caused by some internal layout code for checking the validity (or just computing the effects) of that use of packed)

@pnkfelix pnkfelix changed the title error: internal compiler error: inference variables in nalgebra::base::matrix::Matrix<f32, nalgebra::base::dimension::U3, nalgebra::base::dimension::U1, nalgebra::base::array_storage::ArrayStorage<_, _, _>> error: internal compiler error: "inference variables in ..." on packed type Jun 11, 2019
@pnkfelix
Copy link
Member

(Also, bisection on my mac has shown this was injected by PR #44884 )

pnkfelix added a commit to pnkfelix/rust that referenced this issue Jun 28, 2019
for last-field, rather than even a delayed ICE.

Fix rust-lang#61402.
arielb1 added a commit to arielb1/rust that referenced this issue Jun 29, 2019
Normalization can leave some type-vars unresolved in its return type.
Make sure to resolve them so we have an infcx-independent type that can
be used with `needs_drop`.

Fixes rust-lang#61402.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
wfcheck: resolve the type-vars in `AdtField` types

Normalization can leave some type-vars unresolved in its return type.
Make sure to resolve them so we have an infcx-independent type that can
be used with `needs_drop`.

Fixes rust-lang#61402.

Closes rust-lang#62212 - this PR fixes the root cause.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
wfcheck: resolve the type-vars in `AdtField` types

Normalization can leave some type-vars unresolved in its return type.
Make sure to resolve them so we have an infcx-independent type that can
be used with `needs_drop`.

Fixes rust-lang#61402.

Closes rust-lang#62212 - this PR fixes the root cause.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
wfcheck: resolve the type-vars in `AdtField` types

Normalization can leave some type-vars unresolved in its return type.
Make sure to resolve them so we have an infcx-independent type that can
be used with `needs_drop`.

Fixes rust-lang#61402.

Closes rust-lang#62212 - this PR fixes the root cause.
Centril added a commit to Centril/rust that referenced this issue Jul 3, 2019
wfcheck: resolve the type-vars in `AdtField` types

Normalization can leave some type-vars unresolved in its return type.
Make sure to resolve them so we have an infcx-independent type that can
be used with `needs_drop`.

Fixes rust-lang#61402.

Closes rust-lang#62212 - this PR fixes the root cause.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inference Area: Type inference C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
5 participants