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: Invalid 'Const' during codegen: UnevaluatedConst {..} #129857

Open
matthiaskrgr opened this issue Sep 1, 2024 · 2 comments
Open

ICE: Invalid 'Const' during codegen: UnevaluatedConst {..} #129857

matthiaskrgr opened this issue Sep 1, 2024 · 2 comments
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs, generic_arg_infer)]

use core::mem::MaybeUninit;

pub struct Arr<T, const N: usize> {
    v: [MaybeUninit<T>; N],
}

impl<T, const N: usize> Arr<T, N> {
    const ELEM: MaybeUninit<T> = MaybeUninit::uninit();
    const INIT: [MaybeUninit<T>; N] = [Self::ELEM; N];

    fn new() -> Self {
        Arr { v: Self::INIT }
    }
}

pub struct BaFormatFilter<const N: usize> {}

pub enum DigitalFilter<const N: usize>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    Ba(BaFormatFilter<{ N * 2 + 1 }>),
}

pub fn iirfilter_st_copy<const N: usize, const M: usize>(_: [f32; M]) -> DigitalFilter<N>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    let zpk = zpk2tf_st(&Arr::<f32, { N * 2 }>::new(), &Arr::<f32, { N * 2 }>::new());
    DigitalFilter::Ba(zpk)
}

pub fn zpk2tf_st<const N: usize>(_z: &Arr<f32, N>, _p: &Arr<f32, N>) -> BaFormatFilter<{ N + 1 }> {
    BaFormatFilter {}
}

fn main() {
    iirfilter_st_copy::<4, 2>([10., 50.]);
}
original code

original:

// issue: rust-lang/rust#106423
// ICE collection encountered polymorphic constant: UnevaluatedConst {..}
//@ edition:2021
//@ check-pass

#![feature(generic_const_exprs, generic_arg_infer)]
#![allow(incomplete_features)]
#![allow(unused)]

use core::mem::MaybeUninit;

pub struct Arr<T, const N: usize> {
    v: [MaybeUninit<T>; N],
}

impl<T, const N: usize> Arr<T, N> {
    const ELEM: MaybeUninit<T> = MaybeUninit::uninit();
    const INIT: [MaybeUninit<T>; N] = [Self::ELEM; N]; // important for optimization of `new`

    fn new() -> Self {
        Arr { v: Self::INIT }
    }
}

pub struct BaFormatFilter<const N: usize> {}

pub enum DigitalFilter<const N: usize>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    Ba(BaFormatFilter<{ N * 2 + 1 }>),
}

pub fn iirfilter_st_copy<const N: usize, const M: usize>(_: [f32; M]) -> DigitalFilter<N>
where
    [(); N * 2 + 1]: Sized,
    [(); N * 2]: Sized,
{
    let zpk = zpk2tf_st(&Arr::<f32, { N * 2 }>::new(), &Arr::<f32, { N * 2 }>::new());
    DigitalFilter::Ba(zpk)
}

pub fn zpk2tf_st<const N: usize>(
    _z: &Arr<f32, N>,
    _p: &Arr<f32, N>,
) -> BaFormatFilter<{ N + 1 }>
where
    [(); N + 1]: Sized,
{
    BaFormatFilter {}
}


fn main() {
    iirfilter_st_copy::<4, 2>([10., 50.,]);
}

Version information

rustc 1.83.0-nightly (1a1cc050d 2024-09-01)
binary: rustc
commit-hash: 1a1cc050d8efc906ede39f444936ade1fdc9c6cb
commit-date: 2024-09-01
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zincremental-verify-ich=yes -Cincremental=<dir> -Cdebuginfo=2 -Clink-dead-code=true -Zvalidate-mir --edition=2021

Program output

warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes
 --> /tmp/icemaker_global_tempdir.40eYA5W2oIUb/rustc_testrunner_tmpdir_reporting.DqRxcpiOUpwU/mvce.rs:1:12
  |
1 | #![feature(generic_const_exprs, generic_arg_infer)]
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: see issue #76560 <https://github.com/rust-lang/rust/issues/76560> for more information
  = note: `#[warn(incomplete_features)]` on by default

warning: field `v` is never read
 --> /tmp/icemaker_global_tempdir.40eYA5W2oIUb/rustc_testrunner_tmpdir_reporting.DqRxcpiOUpwU/mvce.rs:6:5
  |
5 | pub struct Arr<T, const N: usize> {
  |            --- field in this struct
6 |     v: [MaybeUninit<T>; N],
  |     ^
  |
  = note: `#[warn(dead_code)]` on by default

error: internal compiler error: compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs:739:14: Invalid `Const` during codegen: UnevaluatedConst { def: DefId(0:37 ~ mvce[36f5]::zpk2tf_st::{constant#0}), args: [(Mul: (4_usize: usize), (2_usize: usize))] }

thread 'rustc' panicked at compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs:739:14:
Box<dyn Any>
stack backtrace:
   0:     0x7ba9a8ffeb2a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hd80d83efaa4dd6d3
   1:     0x7ba9a9803157 - core::fmt::write::h4f2fc0d8a4bdbc07
   2:     0x7ba9aaa9d211 - std::io::Write::write_fmt::h5570f2f97ed637ef
   3:     0x7ba9a90011fb - std::panicking::default_hook::{{closure}}::hbf64d79aec33952e
   4:     0x7ba9a9000e6e - std::panicking::default_hook::h80f8634d4a0460dc
   5:     0x7ba9a81618a9 - std[5b205b49935b963f]::panicking::update_hook::<alloc[3fe16f20e15296c8]::boxed::Box<rustc_driver_impl[27278ae619702df]::install_ice_hook::{closure#0}>>::{closure#0}
   6:     0x7ba9a9001b17 - std::panicking::rust_panic_with_hook::hac455baedf27b84b
   7:     0x7ba9a819bb71 - std[5b205b49935b963f]::panicking::begin_panic::<rustc_errors[b46f225bc36daaa0]::ExplicitBug>::{closure#0}
   8:     0x7ba9a818f096 - std[5b205b49935b963f]::sys::backtrace::__rust_end_short_backtrace::<std[5b205b49935b963f]::panicking::begin_panic<rustc_errors[b46f225bc36daaa0]::ExplicitBug>::{closure#0}, !>
   9:     0x7ba9a818f046 - std[5b205b49935b963f]::panicking::begin_panic::<rustc_errors[b46f225bc36daaa0]::ExplicitBug>
  10:     0x7ba9a81a4df1 - <rustc_errors[b46f225bc36daaa0]::diagnostic::BugAbort as rustc_errors[b46f225bc36daaa0]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  11:     0x7ba9a876d054 - rustc_middle[fdfbfe13c471c215]::util::bug::opt_span_bug_fmt::<rustc_span[682bbc8ac5595dcb]::span_encoding::Span>::{closure#0}
  12:     0x7ba9a8752c0a - rustc_middle[fdfbfe13c471c215]::ty::context::tls::with_opt::<rustc_middle[fdfbfe13c471c215]::util::bug::opt_span_bug_fmt<rustc_span[682bbc8ac5595dcb]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  13:     0x7ba9a8752abb - rustc_middle[fdfbfe13c471c215]::ty::context::tls::with_context_opt::<rustc_middle[fdfbfe13c471c215]::ty::context::tls::with_opt<rustc_middle[fdfbfe13c471c215]::util::bug::opt_span_bug_fmt<rustc_span[682bbc8ac5595dcb]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  14:     0x7ba9a62e4750 - rustc_middle[fdfbfe13c471c215]::util::bug::bug_fmt
  15:     0x7ba9a9fae940 - rustc_codegen_ssa[3363d47dc11c3c03]::debuginfo::type_names::push_generic_params_internal
  16:     0x7ba9a9f90c1a - rustc_codegen_llvm[35a5f2b3be35e22b]::debuginfo::metadata::build_struct_type_di_node
  17:     0x7ba9a9f9f73d - rustc_codegen_llvm[35a5f2b3be35e22b]::debuginfo::metadata::type_di_node
  18:     0x7ba9aa744941 - rustc_codegen_ssa[3363d47dc11c3c03]::mir::codegen_mir::<rustc_codegen_llvm[35a5f2b3be35e22b]::builder::Builder>
  19:     0x7ba9aa73fa35 - rustc_codegen_llvm[35a5f2b3be35e22b]::base::compile_codegen_unit::module_codegen
  20:     0x7ba9aa7be70d - <rustc_codegen_llvm[35a5f2b3be35e22b]::LlvmCodegenBackend as rustc_codegen_ssa[3363d47dc11c3c03]::traits::backend::ExtraBackendMethods>::compile_codegen_unit
  21:     0x7ba9aa7bad84 - <rustc_codegen_llvm[35a5f2b3be35e22b]::LlvmCodegenBackend as rustc_codegen_ssa[3363d47dc11c3c03]::traits::backend::CodegenBackend>::codegen_crate
  22:     0x7ba9aa99a070 - <rustc_interface[561bcd00c1a26bfb]::queries::Linker>::codegen_and_build_linker
  23:     0x7ba9aa5c9a1b - rustc_interface[561bcd00c1a26bfb]::interface::run_compiler::<core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>, rustc_driver_impl[27278ae619702df]::run_compiler::{closure#0}>::{closure#1}
  24:     0x7ba9aa673dd0 - std[5b205b49935b963f]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[561bcd00c1a26bfb]::util::run_in_thread_with_globals<rustc_interface[561bcd00c1a26bfb]::util::run_in_thread_pool_with_globals<rustc_interface[561bcd00c1a26bfb]::interface::run_compiler<core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>, rustc_driver_impl[27278ae619702df]::run_compiler::{closure#0}>::{closure#1}, core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>>::{closure#0}, core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>>
  25:     0x7ba9aa67443a - <<std[5b205b49935b963f]::thread::Builder>::spawn_unchecked_<rustc_interface[561bcd00c1a26bfb]::util::run_in_thread_with_globals<rustc_interface[561bcd00c1a26bfb]::util::run_in_thread_pool_with_globals<rustc_interface[561bcd00c1a26bfb]::interface::run_compiler<core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>, rustc_driver_impl[27278ae619702df]::run_compiler::{closure#0}>::{closure#1}, core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>>::{closure#0}, core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[42bb5247f35782d4]::result::Result<(), rustc_span[682bbc8ac5595dcb]::ErrorGuaranteed>>::{closure#1} as core[42bb5247f35782d4]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  26:     0x7ba9aa6747ab - std::sys::pal::unix::thread::Thread::new::thread_start::h59b1848733925366
  27:     0x7ba9abcdf39d - <unknown>
  28:     0x7ba9abd6449c - <unknown>
  29:                0x0 - <unknown>

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: please make sure that you have updated to the latest nightly

note: rustc 1.83.0-nightly (1a1cc050d 2024-09-01) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z incremental-verify-ich=yes -C incremental=[REDACTED] -C debuginfo=2 -C link-dead-code=true -Z validate-mir

query stack during panic:
end of query stack
error: aborting due to 1 previous error; 2 warnings emitted


@rustbot label +F-generic_const_exprs +F-generic_arg_infer

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Sep 1, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` labels Sep 1, 2024
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Sep 1, 2024

just crashes with --edition=2021 --Cdebuginfo=2 already 🤔

@matthiaskrgr matthiaskrgr added the A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) label Sep 1, 2024
@matthiaskrgr
Copy link
Member Author

nightly-2022-11-27

commit[0] 2022-11-25: Auto merge of #104902 - matthiaskrgr:rollup-oo27a4u, r=matthiaskrgr
commit[1] 2022-11-25: Auto merge of #99798 - JulianKnodt:ac1, r=BoxyUwU
commit[2] 2022-11-26: Auto merge of #104431 - alistair23:alistair/rv64-profiler, r=Mark-Simulacrum
commit[3] 2022-11-26: Auto merge of #104730 - petrochenkov:modchild5, r=cjgillot
commit[4] 2022-11-26: Auto merge of #103556 - clubby789:specialize-option-partial-eq, r=scottmcm
commit[5] 2022-11-26: Auto merge of #104935 - matthiaskrgr:rollup-nuca86l, r=matthiaskrgr
commit[6] 2022-11-26: Auto merge of #104731 - compiler-errors:early-binder-iter-size-hint, r=cjgillot
commit[7] 2022-11-26: Auto merge of #104945 - GuillaumeGomez:rollup-ygzbpbe, r=GuillaumeGomez
ERROR: no CI builds available between 8681d4c and 80a9646 within last 167 days

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) C-bug Category: This is a bug. F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` F-generic_const_exprs `#![feature(generic_const_exprs)]` 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.
Projects
None yet
Development

No branches or pull requests

3 participants