rust-lang / rust-lang/rust

ICE: `Invalid 'Const' during codegen: UnevaluatedConst {..}`

Open
#129,857 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-debuginfo C-bug F-generic_const_exprs I-ICE P-low T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reduced 2.rs reproducer and the panic location in compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs:739. Run it with the listed nightly compiler flags, then trace how the UnevaluatedConst reaches debuginfo type-name generation. Done means the reproducer no longer causes an internal compiler error under that command.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.