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 when compiling nalgebra 0.25.4 in Release mode #100550

Closed
aabizri opened this issue Aug 14, 2022 · 12 comments · Fixed by #100571
Closed

ICE when compiling nalgebra 0.25.4 in Release mode #100550

aabizri opened this issue Aug 14, 2022 · 12 comments · Fixed by #100571
Assignees
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-critical Critical priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Milestone

Comments

@aabizri
Copy link

aabizri commented Aug 14, 2022

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

@aabizri aabizri added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 14, 2022
@compiler-errors
Copy link
Member

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

@ehuss
Copy link
Contributor

ehuss commented Aug 14, 2022

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

@Mark-Simulacrum
Copy link
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.

@Mark-Simulacrum Mark-Simulacrum added this to the 1.64.0 milestone Aug 14, 2022
@Mark-Simulacrum Mark-Simulacrum added the regression-from-stable-to-beta Performance or correctness regression from stable to beta. label Aug 14, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 14, 2022
@cjgillot cjgillot self-assigned this Aug 15, 2022
@compiler-errors
Copy link
Member

Bisected to #99014 which is likely #96856

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

@cjgillot
Copy link
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?

@Noratrieb
Copy link
Member

Noratrieb commented Aug 15, 2022

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

Edit: It's not fixed.

@Mark-Simulacrum
Copy link
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?

@cjgillot
Copy link
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.

@Noratrieb
Copy link
Member

Noratrieb commented Aug 15, 2022

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.

@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-critical

@rustbot rustbot added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Aug 17, 2022
@steffahn
Copy link
Member

steffahn commented Aug 19, 2022

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

@rustbot rustbot added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Aug 19, 2022
@matthiaskrgr
Copy link
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 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-critical Critical priority regression-from-stable-to-beta Performance or correctness regression from stable to beta. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.