Skip to content

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

Description

@zao

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.

Activity

  1. added
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on May 31, 2019
  2. 197g commented on Jun 2, 2019

    @197g
    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.

  3. pnkfelix commented on Jun 6, 2019

    @pnkfelix
    Contributor

    This ICE itself arises from this line:

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

  4. pnkfelix commented on Jun 6, 2019

    @pnkfelix
    Contributor

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

  5. self-assigned this
    on Jun 6, 2019
  6. pnkfelix commented on Jun 11, 2019

    @pnkfelix
    Contributor

    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!"); }
  7. pnkfelix commented on Jun 11, 2019

    @pnkfelix
    Contributor

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

  8. pnkfelix commented on Jun 11, 2019

    @pnkfelix
    Contributor

    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)

  9. 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[/+] on Jun 11, 2019
  10. pnkfelix commented on Jun 17, 2019

    @pnkfelix
    Contributor

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

  11. added a commit that references this issue on Jun 28, 2019
    4925e4a
  12. added 4 commits that reference this issue on Jul 3, 2019
    ea3bee0
    da75e72
    8db468a
    6cfd474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-inferenceArea: Type inferenceC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions