Skip to content

ICE when compiling nalgebra 0.25.4 in Release mode #100550

Description

@aabizri

Code

ICE is triggered when building nalgebra 0.25.4 in file src\geometry\quaternion.rs in release mode. I'm not able to reproduce when building in debug mode. In my situation, the nalgebra crate is built as part of the dependency tree for a binary crate.

Meta

rustc --version --verbose:

<version>
rustc 1.65.0-nightly (75b7e52e9 2022-08-13)
binary: rustc
commit-hash: 75b7e52e92c3b00fc891b47f5b2efdff0a2be55a
commit-date: 2022-08-13
host: x86_64-pc-windows-msvc
release: 1.65.0-nightly
LLVM version: 15.0.0

Error output

error: internal compiler error: no errors encountered even though `delay_span_bug` issued

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:23009 ~ nalgebra[f868]::geometry::quaternion_ops::{impl#40}::mul), const_param_did: None }) (end of phase transition to Optimized) at bb6[22]:
                                Field projection `(*_25).field[0]` specified type `base::matrix::Matrix<N, base::dimension::U4, base::dimension::U1, base::array_storage::ArrayStorage<N, base::dimension::U4, base::dimension::U1>>`, but actual type is base::matrix::Matrix<N, base::dimension::U4, base::dimension::U1, <base::default_allocator::DefaultAllocator as base::allocator::Allocator<N, base::dimension::U4>>::Buffer>
   --> C:\Users\alexandre\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.25.4\src\geometry\quaternion.rs:197:9
    |
197 |         self.coords[3]
    |         ^^^^^^^^^^^
    |
   ::: C:\Users\alexandre\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.25.4\src\geometry\quaternion_ops.rs:388:13
    |
388 |         t * self.as_ref().scalar() + cross + rhs
    |             ---------------------- in this inlined function call
    |
    = note: delayed at compiler\rustc_const_eval\src\transform\validate.rs:129:36

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:22868 ~ nalgebra[f868]::geometry::quaternion_ops::{impl#12}::mul), const_param_did: None }) (end of phase transition to Optimized) at bb0[11]:
                                Field projection `(*_9).field[0]` specified type `base::matrix::Matrix<N, base::dimension::U4, base::dimension::U1, base::array_storage::ArrayStorage<N, base::dimension::U4, base::dimension::U1>>`, but actual type is base::matrix::Matrix<N, base::dimension::U4, base::dimension::U1, <base::default_allocator::DefaultAllocator as base::allocator::Allocator<N, base::dimension::U4>>::Buffer>
   --> C:\Users\alexandre\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.25.4\src\geometry\quaternion_ops.rs:70:10
    |
70  |         &self.coords[i]
    |          ^^^^^^^^^^^
...
163 |         self[3] * rhs[3] - self[0] * rhs[0] - self[1] * rhs[1] - self[2] * rhs[2],
    |         ------- in this inlined function call
    |
    = note: delayed at compiler\rustc_const_eval\src\transform\validate.rs:129:36

[ many other error: internal compiler error: broken MIR in Item ... nalgebra-0.25.4\src\geometry\quaternion.rs ... delayed at compiler\rustc_const_eval\src\transform\validate.rs:129:36 ]

error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:23718 ~ nalgebra[f868]::geometry::dual_quaternion_ops::{impl#119}::mul_assign), const_param_did: None }) (end of phase transition to Optimized) at bb2[2]:
                                Field projection `_6.field[0]` specified type `base::matrix::Matrix<N, base::dimension::U4, base::dimension::U1, base::array_storage::ArrayStorage<N, base::dimension::U4, base::dimension::U1>>`, but actual type is base::matrix::Matrix<N, base::dimension::U4, base::dimension::U1, <base::default_allocator::DefaultAllocator as base::allocator::Allocator<N, base::dimension::U4>>::Buffer>
    --> C:\Users\alexandre\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.25.4\src\geometry\quaternion.rs:29:23
     |
29   | #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
     |                       ^^^^^
     |
    ::: C:\Users\alexandre\.cargo\registry\src\github.com-1ecc6299db9ec823\nalgebra-0.25.4\src\geometry\dual_quaternion_ops.rs:1123:14
     |
1123 |     *self *= rhs.clone(); 'b);
     |              ----------- in this inlined function call
     |
     = note: delayed at compiler\rustc_const_eval\src\transform\validate.rs:129:36

[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.65.0-nightly (75b7e52e9 2022-08-13) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type lib -C opt-level=3 -C linker-plugin-lto -C codegen-units=1

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

query stack during panic:
end of query stack
error: could not compile `nalgebra`
warning: build failed, waiting for other jobs to finish...
Backtrace

<backtrace>
thread 'rustc' panicked at 'Box<dyn Any>', compiler\rustc_errors\src\lib.rs:1425:13
stack backtrace:
   0:     0x7ff9c0749582 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hef430966cfd40ac8
   1:     0x7ff9c07848fb - core::fmt::write::h08e7466f952b94e4
   2:     0x7ff9c073c1ca - <std::io::IoSliceMut as core::fmt::Debug>::fmt::heb4f98fe9372c10e
   3:     0x7ff9c074cf04 - std::panicking::default_hook::hf1a1189a353bdc32
   4:     0x7ff9c074cb3a - std::panicking::default_hook::hf1a1189a353bdc32
   5:     0x7ff9695685b2 - rustc_driver[7ff512c552c17f15]::describe_lints
   6:     0x7ff9c074d902 - std::panicking::rust_panic_with_hook::h67d909907cf690e1
   7:     0x7ff96b8916b3 - <rustc_errors[245989d7d338c5df]::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter>::ui_testing
   8:     0x7ff96b891659 - <rustc_errors[245989d7d338c5df]::annotate_snippet_emitter_writer::AnnotateSnippetEmitterWriter>::ui_testing
   9:     0x7ff96b885cc9 - <rustc_errors[245989d7d338c5df]::emitter::FileWithAnnotatedLines as core[d233d27e09fbdb12]::fmt::Debug>::fmt
  10:     0x7ff96b87b919 - <rustc_feature[c68d06452a2c172]::builtin_attrs::AttributeType as core[d233d27e09fbdb12]::fmt::Debug>::fmt
  11:     0x7ff967d18ea7 - <rustc_errors[245989d7d338c5df]::HandlerInner as core[d233d27e09fbdb12]::ops::drop::Drop>::drop
  12:     0x7ff966e482c9 - <unknown>
  13:     0x7ff966e4af6f - <unknown>
  14:     0x7ff966e2601d - <unknown>
  15:     0x7ff966e232ac - <unknown>
  16:     0x7ff966e27c22 - <unknown>
  17:     0x7ff966e5d6f7 - rustc_driver[7ff512c552c17f15]::args::arg_expand_all
  18:     0x7ff966e26409 - <unknown>
  19:     0x7ff966e4cbfd - <unknown>
  20:     0x7ff9c075e0cc - std::sys::windows::thread::Thread::new::h92481c9c665bb623
  21:     0x7ffa63ac54e0 - BaseThreadInitThunk
  22:     0x7ffa6492485b - RtlUserThreadStart

Activity

  1. added
    C-bugCategory: This is a bug.
    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 Aug 14, 2022
  2. compiler-errors commented on Aug 14, 2022

    @compiler-errors
    Contributor

    cc @cjgillot this seems like those mir-inliner bugs 🤔

  3. ehuss commented on Aug 14, 2022

    @ehuss
    Contributor

    Bisected to #99014 which is likely #96856 (similar as issues #99866 and #99852).

  4. Mark-Simulacrum commented on Aug 14, 2022

    @Mark-Simulacrum
    Member

    Saw a couple of these in Crater, though typically with some other ICEs too (which is why I didn't file bugs). But tagging as 1.64 and beta regression.

  5. added this to the 1.64.0 milestone on Aug 14, 2022
  6. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 14, 2022
  7. self-assigned this
    on Aug 15, 2022
  8. compiler-errors commented on Aug 15, 2022

    @compiler-errors
    Contributor

    Bisected to #99014 which is likely #96856

    For the record, that PR probably revealed this bug but is likely not the cause of it.

  9. cjgillot commented on Aug 15, 2022

    @cjgillot
    Contributor

    Indeed, that's the "usual" normalization failure ICE we have with the MIR inliner.
    When enabling the MIR inliner, I only added a check that we don't have such type mismatch at the signature, but I did not attempt to check all types that appear in the MIR for such mismatch.
    If we want to fully avoid this ICE, we'd need to fully visit the callee body to check for those type mismatches.

    @compiler-errors do you know if progress has been made on the normalization front?

  10. Noratrieb commented on Aug 15, 2022

    @Noratrieb
    Member

    Hmm, maybe this is fixed by #100121, but I don't have time to investigate this right now.

    Edit: It's not fixed.

  11. Mark-Simulacrum commented on Aug 15, 2022

    @Mark-Simulacrum
    Member

    @cjgillot Do you think it may make sense to disable the MIR inliner on beta to give it some more time to bake? I think it was switched on mid-cycle in 1.64, right?

  12. cjgillot commented on Aug 15, 2022

    @cjgillot
    Contributor

    @Mark-Simulacrum I qualify this as a bug in type normalization that MIR validation exposes. It's not a bug in the MIR inliner.

    There are 3 ways to address this:

    1. add more exceptions to the MIR inliner to avoid those bugs (easy but cumbersome, Check projection types before inlining MIR #100571);
    2. fix type normalization (very hard);
    3. relax MIR validation (tentative in Try normalizing types without RevealAll in ParamEnv in MIR validation #100121);
    4. stop validating MIR in released compilers but keep doing it on tests (very easy).

    However, I don't think that disabling the MIR inliner will help.

  13. Noratrieb commented on Aug 15, 2022

    @Noratrieb
    Member

    Stopping to validate MIR sounds like a really bad idea to me. MIR validation (in released compilers) has caught many critical issues already like #98608 (I found it while investigating a MIR validation failure that someone found in the wild because the mir typeck found something typeck let through) and the most recent let_chains problem which was also found because of a MIR validation ICE.

  14. apiraino commented on Aug 17, 2022

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-critical

  15. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Aug 17, 2022
  16. steffahn commented on Aug 19, 2022

    @steffahn
    Member

    Reduced example:

    pub trait Trait {
        type Associated;
    }
    impl<T> Trait for T {
        type Associated = T;
    }
    
    pub struct Struct<T>(<T as Trait>::Associated);
    
    pub fn foo<T>() -> Struct<T>
    where
        T: Trait,
    {
        bar()
    }
    
    #[inline]
    fn bar<T>() -> Struct<T> {
        Struct(baz())
    }
    
    fn baz<T>() -> T {
        unimplemented!()
    }

    playground

       Compiling playground v0.0.1 (/playground)
    error: internal compiler error: no errors encountered even though `delay_span_bug` issued
    
    error: internal compiler error: broken MIR in Item(WithOptConstParam { did: DefId(0:12 ~ playground[dc12]::foo), const_param_did: None }) (end of phase transition to Optimized) at bb1[1]:
                                    Field projection `_0.field[0]` specified type `T`, but actual type is <T as Trait>::Associated
      --> src/lib.rs:19:5
       |
    14 |     bar()
       |     ----- in this inlined function call
    ...
    19 |     Struct(baz())
       |     ^^^^^^^^^^^^^
       |
       = note: delayed at compiler/rustc_const_eval/src/transform/validate.rs:129:36
    
    thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1426:13
    stack backtrace:
       0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
       1: std::panic::panic_any::<rustc_errors::ExplicitBug>
       2: <rustc_errors::HandlerInner as core::ops::drop::Drop>::drop
       3: core::ptr::drop_in_place::<rustc_session::parse::ParseSess>
       4: <alloc::rc::Rc<rustc_session::session::Session> as core::ops::drop::Drop>::drop
       5: core::ptr::drop_in_place::<rustc_interface::interface::Compiler>
       6: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
       7: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>
       8: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
    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.64.0-beta.2 (fb2194acc 2022-08-14) running on x86_64-unknown-linux-gnu
    
    note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C codegen-units=1
    
    note: some of the compiler flags provided by cargo are hidden
    
    query stack during panic:
    end of query stack
    error: could not compile `playground`
    

    @rustbot label S-bug-has-mcve

  17. added
    S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issue
    on Aug 19, 2022
  18. matthiaskrgr commented on Aug 19, 2022

    @matthiaskrgr
    Member

    Weird, this one crashes with --crate-type lib -Copt-level=2 but I couldn't get this to trigger with just mir-opt-levels 🤔

  19. added a commit that references this issue on Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-criticalCritical priorityS-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.glacierICE tracked in rust-lang/glacier.regression-from-stable-to-betaPerformance or correctness regression from stable to beta.

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions