rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.67k stars 12.75k forks source link

ICE: `collection encountered polymorphic constant: Ty(..)` #126696

Open matthiaskrgr opened 5 months ago

matthiaskrgr commented 5 months ago

auto-reduced (treereduce-rust):

#![feature(generic_const_exprs)]

use std::array;

trait PrimRec<const N: usize, const O: usize> {
    fn eval(&self, x: [usize; N]) -> [usize; O];
}

struct Zero;

impl<const N: usize> PrimRec<N, 1> for Zero {
    fn eval(&self, _: [usize; N]) -> [usize; 1] {
        [0]
    }
}

struct S;

impl PrimRec<1, 1> for S {
    fn eval(&self, x: [usize; 1]) -> [usize; 1] {
        [x[0] + 1]
    }
}

struct Proj<const I: usize>;

impl<const N: usize, const I: usize> PrimRec<N, 1> for Proj<I> {
    fn eval(&self, x: [usize; N]) -> [usize; 1] {
        [x[I]]
    }
}

fn concat<const M: usize, const N: usize>(a: [usize; M], b: [usize; N]) -> [usize; M + N] {
    array::from_fn(|i| if i < M { a[i] } else { b[i - M] })
}

struct Compose<const N: usize, const I: usize, const O: usize, A, B>(A, B);

impl<const N: usize, const I: usize, const O: usize, A: PrimRec<N, I>, B: PrimRec<I, O>>
    PrimRec<N, O> for Compose<N, I, O, A, B>
{
    fn eval(&self, x: [usize; N]) -> [usize; O] {
        self.1.eval(self.0.eval(x))
    }
}

struct Rec<const N: usize, const O: usize, Base, F>(Base, F);

fn tail<const N: usize>(x: [usize; N + 1]) -> [usize; N] {
    array::from_fn(|i| x[i + 1])
}

fn cons<const N: usize>(x: usize, xs: [usize; N]) -> [usize; N + 1] {
    array::from_fn(|i| if i == 0 { x } else { xs[i - 1] })
}

impl<const N: usize, const O: usize, Base, F: PrimRec<{ O + (N + 1) }, O>> PrimRec<{ N + 1 }, O>
    for Rec<N, O, Base, F>
{
    fn eval(&self, x: [usize; N + 1]) -> [usize; O] {
        match (x[0], tail(x)) {
            (y, x) => {
                let xy = cons(y - 1, x);
                let input = concat(self.eval(xy), xy);
                self.1.eval(input)
            }
        }
    }
}

fn main() {
    let one = Compose(Zero, S);
    dbg!(one.eval([]));
    let add: Rec<1, 1, Proj<0>, Compose<3, 1, 1, Proj<0>, S>> =
        Rec(Proj::<0>, Compose(Proj::<0>, S));
    dbg!(add.eval([3, 2]));
}
original code

original: ````rust #![feature(generic_const_exprs)] use std::array; trait PrimRec { fn eval(&self, x: [usize; N]) -> [usize; O]; } struct Zero; impl PrimRec for Zero { fn eval(&self, _: [usize; N]) -> [usize; 1] { [0] } } struct Const(usize); impl PrimRec for Const { fn eval(&self, _: [usize; N]) -> [usize; 1] { [self.0] } } struct S; impl PrimRec<1, 1> for S { fn eval(&self, x: [usize; 1]) -> [usize; 1] { [x[0] + 1] } } struct Proj; impl PrimRec for Proj { fn eval(&self, x: [usize; N]) -> [usize; 1] { [x[I]] } } struct Merge, B: PrimRec>( A, B, ); fn concat(a: [usize; M], b: [usize; N]) -> [usize; M + N] { array::from_fn(|i| if i < M { a[i] } else { b[i - M] }) } impl, B: PrimRec> PrimRec for Merge { fn eval(&self, x: [usize; N]) -> [usize; O1 + O2] { concat(self.0.eval(x), self.1.eval(x)) } } struct Compose, B: PrimRec>( A, B, ); impl, B: PrimRec> PrimRec for Compose { fn eval(&self, x: [usize; N]) -> [usize; O] { self.1.eval(self.0.eval(x)) } } struct Rec, F: PrimRec<{ O + (N + 1) }, O>>( Base, F, ); fn tail(x: [usize; N + 1]) -> [usize; N] { array::from_fn(|i| x[i + 1]) } fn cons(x: usize, xs: [usize; N]) -> [usize; N + 1] { array::from_fn(|i| if i == 0 { x } else { xs[i - 1] }) } impl, F: PrimRec<{ O + (N + 1) }, O>> PrimRec<{ N + 1 }, O> for Rec { fn eval(&self, x: [usize; N + 1]) -> [usize; O] { match (x[0], tail(x)) { (y, x) => { let xy = cons(y - 1, x); let input = concat(self.eval(xy), xy); self.1.eval(input) } (y, x) => { let xy = cons(y - 1, x); let input = concat(self.eval(xy), xy); self.1.eval(input) } } } } fn main() { let one = Compose(Zero, S); dbg!(one.eval([])); let add: Rec<1, 1, Proj<0>, Compose<3, 1, 1, Proj<0>, S>> = Rec(Proj::<0>, Compose(Proj::<0>, S)); dbg!(add.eval([3, 2])); } ````

Version information

rustc 1.81.0-nightly (3186d17d5 2024-06-19)
binary: rustc
commit-hash: 3186d17d56f9803b739a2c0aabd23aafd8791485
commit-date: 2024-06-19
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

Command: /home/matthias/.rustup/toolchains/master/bin/rustc

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.BYeIIN3IDTg1/rustc_testrunner_tmpdir_reporting.pn272iv1coHt/mvce.rs:1:12 | 1 | #![feature(generic_const_exprs)] | ^^^^^^^^^^^^^^^^^^^ | = note: see issue #76560 for more information = note: `#[warn(incomplete_features)]` on by default warning: function cannot return without recursing --> /tmp/icemaker_global_tempdir.BYeIIN3IDTg1/rustc_testrunner_tmpdir_reporting.pn272iv1coHt/mvce.rs:60:5 | 60 | fn eval(&self, x: [usize; N + 1]) -> [usize; O] { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot return without recursing ... 64 | let input = concat(self.eval(xy), xy); | ------------- recursive call site | = help: a `loop` may express intention better if this is on purpose = note: `#[warn(unconditional_recursion)]` on by default error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:703:50: collection encountered polymorphic constant: Ty(usize, (Add: (1_usize: usize), (1_usize: usize))) --> /tmp/icemaker_global_tempdir.BYeIIN3IDTg1/rustc_testrunner_tmpdir_reporting.pn272iv1coHt/mvce.rs:34:49 | 34 | array::from_fn(|i| if i < M { a[i] } else { b[i - M] }) | ^^^^^^^^ thread 'rustc' panicked at compiler/rustc_monomorphize/src/collector.rs:703:50: Box stack backtrace: 0: 0x7e169cf9a915 - std::backtrace_rs::backtrace::libunwind::trace::h7bb2e2c0ba47a528 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7e169cf9a915 - std::backtrace_rs::backtrace::trace_unsynchronized::h4d0192941edee661 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7e169cf9a915 - std::sys::backtrace::_print_fmt::hd97d629aac4a983f at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/sys/backtrace.rs:68:5 3: 0x7e169cf9a915 - ::fmt::hfbfff27250bacb87 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/sys/backtrace.rs:44:22 4: 0x7e169cfeb4bb - core::fmt::rt::Argument::fmt::he10ba4f740dba534 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/core/src/fmt/rt.rs:165:63 5: 0x7e169cfeb4bb - core::fmt::write::h2407ad66766d3825 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/core/src/fmt/mod.rs:1168:21 6: 0x7e169cf8f4ff - std::io::Write::write_fmt::ha9f6e1a0fc7453ce at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/io/mod.rs:1835:15 7: 0x7e169cf9a6ee - std::sys::backtrace::_print::h7e0f8c040736e5d1 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/sys/backtrace.rs:47:5 8: 0x7e169cf9a6ee - std::sys::backtrace::print::h5b5a8173569d0f1f at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/sys/backtrace.rs:34:9 9: 0x7e169cf9d129 - std::panicking::default_hook::{{closure}}::h598070fde84813fd 10: 0x7e169cf9cecc - std::panicking::default_hook::h475a3da7dddfd122 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/panicking.rs:292:9 11: 0x7e169953d430 - std[2bd9c63c0a80de36]::panicking::update_hook::>::{closure#0} 12: 0x7e169cf9da4f - as core::ops::function::Fn>::call::h7852cb703cb16a8a at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/alloc/src/boxed.rs:2076:9 13: 0x7e169cf9da4f - std::panicking::rust_panic_with_hook::h09dcd92a3eced375 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/panicking.rs:804:13 14: 0x7e169956e111 - std[2bd9c63c0a80de36]::panicking::begin_panic::::{closure#0} 15: 0x7e169956aa46 - std[2bd9c63c0a80de36]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7e1699565cd6 - std[2bd9c63c0a80de36]::panicking::begin_panic:: 17: 0x7e16995773b1 - ::emit_producing_guarantee 18: 0x7e1699cea6e8 - ::span_bug:: 19: 0x7e1699cf5f3d - rustc_middle[1e151660401c97c9]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7e1699cf620a - rustc_middle[1e151660401c97c9]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7e1699cf1c5b - rustc_middle[1e151660401c97c9]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7e1699cef657 - rustc_middle[1e151660401c97c9]::util::bug::span_bug_fmt:: 23: 0x7e169b895886 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec::{closure#0} 24: 0x7e169aa8a20a - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 25: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 26: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 27: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 28: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 29: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 30: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 31: 0x7e169aa8a991 - rustc_monomorphize[ce7da5b91994c407]::collector::collect_items_rec 32: 0x7e169afb40b9 - rustc_monomorphize[ce7da5b91994c407]::partitioning::collect_and_partition_mono_items 33: 0x7e169baa5d64 - rustc_query_impl[90e082e217628c6f]::plumbing::__rust_begin_short_backtrace::> 34: 0x7e169baa5d49 - >::call_once 35: 0x7e169baa5908 - rustc_query_system[79f2d7548a1d7730]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[90e082e217628c6f]::plumbing::QueryCtxt, false> 36: 0x7e169baa5621 - rustc_query_impl[90e082e217628c6f]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace 37: 0x7e169b9039d4 - rustc_codegen_ssa[9f248794c5001305]::base::codegen_crate:: 38: 0x7e169b8f8202 - ::codegen_crate 39: 0x7e169b8f7b85 - rustc_interface[f14b298c5bc54b9d]::passes::start_codegen 40: 0x7e169b8f7224 - ::codegen_and_build_linker 41: 0x7e169b6e79f2 - rustc_interface[f14b298c5bc54b9d]::interface::run_compiler::, rustc_driver_impl[9baf949efeffb90b]::run_compiler::{closure#0}>::{closure#1} 42: 0x7e169b6d5ce7 - std[2bd9c63c0a80de36]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[9baf949efeffb90b]::run_compiler::{closure#0}>::{closure#1}, core[86ed06ce5521d24]::result::Result<(), rustc_span[825a5f7bcd5860db]::ErrorGuaranteed>>::{closure#0}, core[86ed06ce5521d24]::result::Result<(), rustc_span[825a5f7bcd5860db]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[86ed06ce5521d24]::result::Result<(), rustc_span[825a5f7bcd5860db]::ErrorGuaranteed>> 43: 0x7e169b6d5aaa - <::spawn_unchecked_, rustc_driver_impl[9baf949efeffb90b]::run_compiler::{closure#0}>::{closure#1}, core[86ed06ce5521d24]::result::Result<(), rustc_span[825a5f7bcd5860db]::ErrorGuaranteed>>::{closure#0}, core[86ed06ce5521d24]::result::Result<(), rustc_span[825a5f7bcd5860db]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[86ed06ce5521d24]::result::Result<(), rustc_span[825a5f7bcd5860db]::ErrorGuaranteed>>::{closure#2} as core[86ed06ce5521d24]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 44: 0x7e169cfa78cb - as core::ops::function::FnOnce>::call_once::h080d8c35a4cd7df7 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/alloc/src/boxed.rs:2062:9 45: 0x7e169cfa78cb - as core::ops::function::FnOnce>::call_once::hbe3e90ec6c687c94 at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/alloc/src/boxed.rs:2062:9 46: 0x7e169cfa78cb - std::sys::pal::unix::thread::Thread::new::thread_start::h9be4fe738a3fe2ed at /rustc/3186d17d56f9803b739a2c0aabd23aafd8791485/library/std/src/sys/pal/unix/thread.rs:108:17 47: 0x7e169cd40ded - 48: 0x7e169cdc40dc - 49: 0x0 - 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.81.0-nightly (3186d17d5 2024-06-19) running on x86_64-unknown-linux-gnu query stack during panic: #0 [collect_and_partition_mono_items] collect_and_partition_mono_items end of query stack error: aborting due to 1 previous error; 2 warnings emitted ```

@rustbot label +F-generic_const_exprs

BoxyUwU commented 5 months ago

This is probably just caused by the fact that we have no way of evaluating ConstKind::Expr

GrigorenkoPV commented 5 months ago

~Regression in nightly-2023-04-21 (39c6804b92aa202369e402525cee329556bc1db0...8bdcc62cb0362869f0e7b43a6ae4f96b953d3cbc)~

nightly-2023-01-10 cc47b069983292e4ee8982d5dabe6301452c5f25...3020239de947ec52677e9b4e853a6a9fc073d1f9

pacak commented 5 months ago

A bit smaller

#![feature(generic_const_exprs)]

trait PrimRec<const N: usize, const O: usize> {
    fn eval(&self) -> [usize; O];
}

fn concat<const M: usize, const N: usize>(_: [usize; M], _: [usize; N]) -> [usize; M + N] {
    [0; M + N]
}

struct Compose<const N: usize, const O: usize>;

impl<const N: usize, const O: usize> PrimRec<N, O> for Compose<N, O> {
    fn eval(&self) -> [usize; O] {
        [0; O]
    }
}

struct Rec<const N: usize, const O: usize>();

impl<const N: usize, const O: usize> PrimRec<{ N + 1 }, O> for Rec<N, O> {
    fn eval(&self) -> [usize; O] {
        concat(self.eval(), [0; N + 1]);
        [0; O]
    }
}

pub fn b() -> [usize; 1] {
    let add: Rec<1, 1, Compose<3, 1>> = Rec(Compose);
    add.eval()
}
theemathas commented 5 months ago

@pacak's code doesn't cause an ICE for me.

Here's my minimized code that causes the ICE:

#![feature(generic_const_exprs)]
#![allow(incomplete_features)]

fn can_double<const N: usize>(x: [(); N])
where
    [(); N * 2]:,
{
    x[0];
    unimplemented!()
}

fn foo<const N: usize>()
where
    [(); (N + 1) * 2]:,
{
    can_double([(); { N + 1 }]);
    // Adding an explicit constant generic causes the ICE to go away
    // can_double::<{N + 1}>([(); { N + 1 }]);
}

fn main() {
    foo::<1>();
}
Error output ``` Compiling playground v0.0.1 (/playground) error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:703:50: collection encountered polymorphic constant: Ty(usize, (Add: (1_usize: usize), (1_usize: usize))) --> src/main.rs:8:5 | 8 | x[0]; | ^^^^ thread 'rustc' panicked at compiler/rustc_monomorphize/src/collector.rs:703:50: Box stack backtrace: 0: 0x7ff2bcd19915 - std::backtrace_rs::backtrace::libunwind::trace::hbd82a583e4f26fdd at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7ff2bcd19915 - std::backtrace_rs::backtrace::trace_unsynchronized::habc2fad340bf99ae at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7ff2bcd19915 - std::sys::backtrace::_print_fmt::h89b7d2a10146c395 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:68:5 3: 0x7ff2bcd19915 - ::fmt::h0c93516475f50c3a at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:44:22 4: 0x7ff2bcd6a4bb - core::fmt::rt::Argument::fmt::h41acc358ea8b8acf at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/core/src/fmt/rt.rs:165:63 5: 0x7ff2bcd6a4bb - core::fmt::write::hf6eeaa81bb552677 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/core/src/fmt/mod.rs:1168:21 6: 0x7ff2bcd0e5af - std::io::Write::write_fmt::hac861e2844721d50 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/io/mod.rs:1835:15 7: 0x7ff2bcd196ee - std::sys::backtrace::_print::h6229f864442f9359 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:47:5 8: 0x7ff2bcd196ee - std::sys::backtrace::print::h9a44e31d3b18ae2d at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:34:9 9: 0x7ff2bcd1c129 - std::panicking::default_hook::{{closure}}::h20f8661b4d66374d 10: 0x7ff2bcd1becc - std::panicking::default_hook::h59184e6792221498 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/panicking.rs:292:9 11: 0x7ff2c00f4070 - std[3ddfefbe1cb24c03]::panicking::update_hook::>::{closure#0} 12: 0x7ff2bcd1ca4f - as core::ops::function::Fn>::call::h56b5dc1f0f840fa9 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/alloc/src/boxed.rs:2076:9 13: 0x7ff2bcd1ca4f - std::panicking::rust_panic_with_hook::heace302572eb89dc at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/panicking.rs:804:13 14: 0x7ff2c01244f1 - std[3ddfefbe1cb24c03]::panicking::begin_panic::::{closure#0} 15: 0x7ff2c0120e26 - std[3ddfefbe1cb24c03]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7ff2c011c0b6 - std[3ddfefbe1cb24c03]::panicking::begin_panic:: 17: 0x7ff2c012d791 - ::emit_producing_guarantee 18: 0x7ff2c08a0b68 - ::span_bug:: 19: 0x7ff2c08ac65d - rustc_middle[af6aec1290961532]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7ff2c08ac68a - rustc_middle[af6aec1290961532]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7ff2c08a80db - rustc_middle[af6aec1290961532]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7ff2c08a75b7 - rustc_middle[af6aec1290961532]::util::bug::span_bug_fmt:: 23: 0x7ff2c2422785 - rustc_monomorphize[a5e864777eed011c]::collector::collect_items_rec::{closure#0} 24: 0x7ff2c1618d4a - rustc_monomorphize[a5e864777eed011c]::collector::collect_items_rec 25: 0x7ff2c16194d1 - rustc_monomorphize[a5e864777eed011c]::collector::collect_items_rec 26: 0x7ff2c16194d1 - rustc_monomorphize[a5e864777eed011c]::collector::collect_items_rec 27: 0x7ff2c1b34879 - rustc_monomorphize[a5e864777eed011c]::partitioning::collect_and_partition_mono_items 28: 0x7ff2c23ebaa4 - rustc_query_impl[7edf4ed5070a390c]::plumbing::__rust_begin_short_backtrace::> 29: 0x7ff2c23eba89 - >::call_once 30: 0x7ff2c23eb648 - rustc_query_system[d8e6f8beb48e4d6e]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[7edf4ed5070a390c]::plumbing::QueryCtxt, false> 31: 0x7ff2c23eb361 - rustc_query_impl[7edf4ed5070a390c]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace 32: 0x7ff2c254e9d4 - rustc_codegen_ssa[24d0c4fb75869fe7]::base::codegen_crate:: 33: 0x7ff2c244c5c2 - ::codegen_crate 34: 0x7ff2c244bf45 - rustc_interface[2eb39444b88eb871]::passes::start_codegen 35: 0x7ff2c244b5da - ::codegen_and_build_linker 36: 0x7ff2c228b0f2 - rustc_interface[2eb39444b88eb871]::interface::run_compiler::, rustc_driver_impl[5444b1bc0927b6c7]::run_compiler::{closure#0}>::{closure#1} 37: 0x7ff2c227b327 - std[3ddfefbe1cb24c03]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[5444b1bc0927b6c7]::run_compiler::{closure#0}>::{closure#1}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>> 38: 0x7ff2c227b0ea - <::spawn_unchecked_, rustc_driver_impl[5444b1bc0927b6c7]::run_compiler::{closure#0}>::{closure#1}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#2} as core[5462992d5ab3101d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 39: 0x7ff2bcd268cb - as core::ops::function::FnOnce>::call_once::hc134ecaff2ab5c22 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/alloc/src/boxed.rs:2062:9 40: 0x7ff2bcd268cb - as core::ops::function::FnOnce>::call_once::h324a3195842effe4 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/alloc/src/boxed.rs:2062:9 41: 0x7ff2bcd268cb - std::sys::pal::unix::thread::Thread::new::thread_start::hc024fbe6956acc0b at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/pal/unix/thread.rs:108:17 42: 0x7ff2bcc34609 - start_thread 43: 0x7ff2bcb57353 - clone 44: 0x0 - 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: please attach the file at `/playground/rustc-ice-2024-06-20T04_52_55-411.txt` to your bug report note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 note: some of the compiler flags provided by cargo are hidden query stack during panic: #0 [collect_and_partition_mono_items] collect_and_partition_mono_items end of query stack error: could not compile `playground` (bin "playground") ```

Additionally, removing the x[0] causes a different ICE. (fn_abi_of_instance(can_double::<1 + 1>, []) failed: Layout(Unknown([(); (Add: (1_usize: usize), (1_usize: usize))])))

Code with `x[0]` removed ```rust #![feature(generic_const_exprs)] #![allow(incomplete_features)] fn can_double(_: [(); N]) where [(); N * 2]:, { unimplemented!() } fn foo() where [(); (N + 1) * 2]:, { can_double([(); { N + 1 }]); // Adding an explicit constant generic causes the ICE to go away // can_double::<{N + 1}>([(); { N + 1 }]); } fn main() { foo::<1>(); } ```
Error output ``` Compiling playground v0.0.1 (/playground) error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:1099:21: `fn_abi_of_instance(can_double::<1 + 1>, [])` failed: Layout(Unknown([(); (Add: (1_usize: usize), (1_usize: usize))])) --> src/main.rs:4:1 | 4 | / fn can_double(_: [(); N]) 5 | | where 6 | | [(); N * 2]:, | |_________________^ thread 'rustc' panicked at compiler/rustc_codegen_llvm/src/context.rs:1099:21: Box stack backtrace: 0: 0x7ff6d8d2d915 - std::backtrace_rs::backtrace::libunwind::trace::hbd82a583e4f26fdd at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5 1: 0x7ff6d8d2d915 - std::backtrace_rs::backtrace::trace_unsynchronized::habc2fad340bf99ae at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x7ff6d8d2d915 - std::sys::backtrace::_print_fmt::h89b7d2a10146c395 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:68:5 3: 0x7ff6d8d2d915 - ::fmt::h0c93516475f50c3a at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:44:22 4: 0x7ff6d8d7e4bb - core::fmt::rt::Argument::fmt::h41acc358ea8b8acf at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/core/src/fmt/rt.rs:165:63 5: 0x7ff6d8d7e4bb - core::fmt::write::hf6eeaa81bb552677 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/core/src/fmt/mod.rs:1168:21 6: 0x7ff6d8d225af - std::io::Write::write_fmt::hac861e2844721d50 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/io/mod.rs:1835:15 7: 0x7ff6d8d2d6ee - std::sys::backtrace::_print::h6229f864442f9359 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:47:5 8: 0x7ff6d8d2d6ee - std::sys::backtrace::print::h9a44e31d3b18ae2d at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/backtrace.rs:34:9 9: 0x7ff6d8d30129 - std::panicking::default_hook::{{closure}}::h20f8661b4d66374d 10: 0x7ff6d8d2fecc - std::panicking::default_hook::h59184e6792221498 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/panicking.rs:292:9 11: 0x7ff6dc108070 - std[3ddfefbe1cb24c03]::panicking::update_hook::>::{closure#0} 12: 0x7ff6d8d30a4f - as core::ops::function::Fn>::call::h56b5dc1f0f840fa9 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/alloc/src/boxed.rs:2076:9 13: 0x7ff6d8d30a4f - std::panicking::rust_panic_with_hook::heace302572eb89dc at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/panicking.rs:804:13 14: 0x7ff6dc1384f1 - std[3ddfefbe1cb24c03]::panicking::begin_panic::::{closure#0} 15: 0x7ff6dc134e26 - std[3ddfefbe1cb24c03]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 16: 0x7ff6dc1300b6 - std[3ddfefbe1cb24c03]::panicking::begin_panic:: 17: 0x7ff6dc141791 - ::emit_producing_guarantee 18: 0x7ff6dbf6f638 - ::span_bug:: 19: 0x7ff6dbf8c96d - rustc_middle[af6aec1290961532]::util::bug::opt_span_bug_fmt::::{closure#0} 20: 0x7ff6dbf8cb9a - rustc_middle[af6aec1290961532]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 21: 0x7ff6dbf8412b - rustc_middle[af6aec1290961532]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 22: 0x7ff6dbf83ba7 - rustc_middle[af6aec1290961532]::util::bug::span_bug_fmt:: 23: 0x7ff6dbfb3284 - ::handle_fn_abi_err 24: 0x7ff6dbf8eaf3 - ::fn_abi_of_instance::{closure#0} 25: 0x7ff6da512cbe - ::predefine_fn 26: 0x7ff6de35f0d9 - rustc_codegen_llvm[92ee7380647a03c4]::base::compile_codegen_unit::module_codegen 27: 0x7ff6de35b416 - ::compile_codegen_unit 28: 0x7ff6de562f87 - rustc_codegen_ssa[24d0c4fb75869fe7]::base::codegen_crate:: 29: 0x7ff6de4605c2 - ::codegen_crate 30: 0x7ff6de45ff45 - rustc_interface[2eb39444b88eb871]::passes::start_codegen 31: 0x7ff6de45f5da - ::codegen_and_build_linker 32: 0x7ff6de29f0f2 - rustc_interface[2eb39444b88eb871]::interface::run_compiler::, rustc_driver_impl[5444b1bc0927b6c7]::run_compiler::{closure#0}>::{closure#1} 33: 0x7ff6de28f327 - std[3ddfefbe1cb24c03]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[5444b1bc0927b6c7]::run_compiler::{closure#0}>::{closure#1}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>> 34: 0x7ff6de28f0ea - <::spawn_unchecked_, rustc_driver_impl[5444b1bc0927b6c7]::run_compiler::{closure#0}>::{closure#1}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5462992d5ab3101d]::result::Result<(), rustc_span[4eb217dce8cff183]::ErrorGuaranteed>>::{closure#2} as core[5462992d5ab3101d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 35: 0x7ff6d8d3a8cb - as core::ops::function::FnOnce>::call_once::hc134ecaff2ab5c22 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/alloc/src/boxed.rs:2062:9 36: 0x7ff6d8d3a8cb - as core::ops::function::FnOnce>::call_once::h324a3195842effe4 at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/alloc/src/boxed.rs:2062:9 37: 0x7ff6d8d3a8cb - std::sys::pal::unix::thread::Thread::new::thread_start::hc024fbe6956acc0b at /rustc/d8a38b00024cd7156dea4ce8fd8ae113a2745e7f/library/std/src/sys/pal/unix/thread.rs:108:17 38: 0x7ff6d8c48609 - start_thread 39: 0x7ff6d8b6b353 - clone 40: 0x0 - 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: please attach the file at `/playground/rustc-ice-2024-06-20T04_56_04-89.txt` to your bug report note: compiler flags: --crate-type bin -C embed-bitcode=no -C codegen-units=1 -C debuginfo=2 note: some of the compiler flags provided by cargo are hidden query stack during panic: end of query stack error: could not compile `playground` (bin "playground") ```