Skip to content

ICE error in Rust compiler: ty::Const::eval called on a non-valtree-compatible type #118285

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

Closed
iamanonymouscs opened this issue Nov 25, 2023 · 8 comments · Fixed by #118498
Closed
Labels
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.

Comments

@iamanonymouscs
Copy link

iamanonymouscs commented Nov 25, 2023

Code

struct Checked<const F: fn(usize) -> bool>;
fn not_one(val: usize) -> bool { val != 1 }
fn not_two(val: usize) -> bool { val != 2 }
fn main() {
    let _ = Checked::<{const _: Checked<not_one> = Checked::<not_one>;
    let _: Checked<not_one> = Checked::<not_two>;
    let _: Checked<not_one> = Checked}>;
    
}

Meta

rustc --version --verbose:

rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-unknown-linux-gnu
release: 1.74.0
LLVM version: 17.0.4

The same problem is reproduced by rustc 1.76.0-nightly (37b2813 2023-11-24).

Error output

error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `}`
 --> code.rs:7:38
  |
7 |     let _: Checked<not_one> = Checked}>;
  |                                      ^ expected one of 8 possible tokens

error: using function pointers as const generic parameters is forbidden
 --> code.rs:1:25
  |
1 | struct Checked<const F: fn(usize) -> bool>;
  |                         ^^^^^^^^^^^^^^^^^
  |
  = note: the only supported types are integers, `bool` and `char`
thread 'rustc' panicked at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/compiler/rustc_middle/src/ty/consts.rs:295:22:
`ty::Const::eval` called on a non-valtree-compatible type
Backtrace

thread 'rustc' panicked at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/compiler/rustc_middle/src/ty/consts.rs:295:22:
`ty::Const::eval` called on a non-valtree-compatible type
stack backtrace:
   0:     0x7f2d78b7e33c - std::backtrace_rs::backtrace::libunwind::trace::h67a838aed1f4d6ec
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f2d78b7e33c - std::backtrace_rs::backtrace::trace_unsynchronized::h1d1786bb1962baf8
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f2d78b7e33c - std::sys_common::backtrace::_print_fmt::h5a0b1f807a002d23
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x7f2d78b7e33c - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf84ab6ad0b91784c
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f2d78be3f9c - core::fmt::rt::Argument::fmt::h28f463bd1fdabed5
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/fmt/rt.rs:138:9
   5:     0x7f2d78be3f9c - core::fmt::write::ha37c23b175e921b3
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/fmt/mod.rs:1114:21
   6:     0x7f2d78b710be - std::io::Write::write_fmt::haa1b000741bcbbe1
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/io/mod.rs:1763:15
   7:     0x7f2d78b7e124 - std::sys_common::backtrace::_print::h1ff1030b04dfb157
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f2d78b7e124 - std::sys_common::backtrace::print::hb982056c6f29541c
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f2d78b81003 - std::panicking::default_hook::{{closure}}::h11f92f82c62fbd68
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:272:22
  10:     0x7f2d78b80d24 - std::panicking::default_hook::hb8810fe276772c66
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:292:9
  11:     0x7f2d7bd196ff - std[75110f2ce3cbb2c9]::panicking::update_hook::<alloc[e150e82988d12314]::boxed::Box<rustc_driver_impl[47b5c41fd5152b42]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f2d78b81831 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h87b887549356728a
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/boxed.rs:2021:9
  13:     0x7f2d78b81831 - std::panicking::rust_panic_with_hook::hd2f0efd2fec86cb0
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:735:13
  14:     0x7f2d78b815b1 - std::panicking::begin_panic_handler::{{closure}}::h3651b7fc4f61d784
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:609:13
  15:     0x7f2d78b7e866 - std::sys_common::backtrace::__rust_end_short_backtrace::hbc468e4b98c7ae04
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys_common/backtrace.rs:170:18
  16:     0x7f2d78b81302 - rust_begin_unwind
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/panicking.rs:597:5
  17:     0x7f2d78be0625 - core::panicking::panic_fmt::h979245e2fdb2fabd
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:72:14
  18:     0x7f2d78be0373 - core::panicking::panic_display::h9b355c58fd35af38
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:168:5
  19:     0x7f2d78be0373 - core::panicking::panic_str::h187a5146d72e7d2f
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/panicking.rs:152:5
  20:     0x7f2d78be0373 - core::option::expect_failed::h7cdfa49208a82a89
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/core/src/option.rs:1988:5
  21:     0x7f2d7a577b57 - <rustc_middle[cfbee9f1a0b252f]::ty::consts::Const>::normalize
  22:     0x7f2d7a574b54 - <rustc_trait_selection[cde77d364afa16a7]::traits::project::AssocTypeNormalizer as rustc_type_ir[22f713ae44c5fda6]::fold::TypeFolder<rustc_middle[cfbee9f1a0b252f]::ty::context::TyCtxt>>::fold_const
  23:     0x7f2d7a55b03f - <&rustc_middle[cfbee9f1a0b252f]::ty::list::List<rustc_middle[cfbee9f1a0b252f]::ty::generic_args::GenericArg> as rustc_type_ir[22f713ae44c5fda6]::fold::TypeFoldable<rustc_middle[cfbee9f1a0b252f]::ty::context::TyCtxt>>::try_fold_with::<rustc_trait_selection[cde77d364afa16a7]::traits::project::AssocTypeNormalizer>
  24:     0x7f2d7a55b454 - <rustc_trait_selection[cde77d364afa16a7]::traits::project::AssocTypeNormalizer as rustc_type_ir[22f713ae44c5fda6]::fold::TypeFolder<rustc_middle[cfbee9f1a0b252f]::ty::context::TyCtxt>>::fold_ty
  25:     0x7f2d7a92c68a - <rustc_trait_selection[cde77d364afa16a7]::traits::engine::ObligationCtxt>::normalize::<rustc_middle[cfbee9f1a0b252f]::ty::Ty>
  26:     0x7f2d7a93f5ae - rustc_hir_analysis[de820db48f542fb9]::check::wfcheck::check_item_type
  27:     0x7f2d7a9220ea - rustc_hir_analysis[de820db48f542fb9]::check::wfcheck::check_well_formed
  28:     0x7f2d79e2248c - rustc_query_impl[252fba113696aa73]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[252fba113696aa73]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cfbee9f1a0b252f]::query::erase::Erased<[u8; 0usize]>>
  29:     0x7f2d7a7cbd7b - rustc_query_system[835e2ed124ae29cf]::query::plumbing::try_execute_query::<rustc_query_impl[252fba113696aa73]::DynamicConfig<rustc_query_system[835e2ed124ae29cf]::query::caches::VecCache<rustc_hir[174f47e87bf43e7f]::hir_id::OwnerId, rustc_middle[cfbee9f1a0b252f]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[252fba113696aa73]::plumbing::QueryCtxt, false>
  30:     0x7f2d7a7cba84 - rustc_query_impl[252fba113696aa73]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  31:     0x7f2d7ad1f8a8 - rustc_data_structures[7bd4ad184b36c2b5]::sync::parallel::disabled::par_for_each_in::<&[rustc_hir[174f47e87bf43e7f]::hir::ImplItemId], <rustc_middle[cfbee9f1a0b252f]::hir::ModuleItems>::par_impl_items<rustc_hir_analysis[de820db48f542fb9]::check::wfcheck::check_mod_type_wf::{closure#1}>::{closure#0}>
  32:     0x7f2d7ad1f597 - rustc_hir_analysis[de820db48f542fb9]::check::wfcheck::check_mod_type_wf
  33:     0x7f2d7ab98c2c - rustc_query_impl[252fba113696aa73]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[252fba113696aa73]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cfbee9f1a0b252f]::query::erase::Erased<[u8; 0usize]>>
  34:     0x7f2d7ab98c0e - <rustc_query_impl[252fba113696aa73]::query_impl::check_mod_type_wf::dynamic_query::{closure#2} as core[5a612027cd243909]::ops::function::FnOnce<(rustc_middle[cfbee9f1a0b252f]::ty::context::TyCtxt, rustc_span[56b754c3614a230e]::def_id::LocalModDefId)>>::call_once
  35:     0x7f2d7ad04ff8 - rustc_query_system[835e2ed124ae29cf]::query::plumbing::try_execute_query::<rustc_query_impl[252fba113696aa73]::DynamicConfig<rustc_query_system[835e2ed124ae29cf]::query::caches::DefaultCache<rustc_span[56b754c3614a230e]::def_id::LocalModDefId, rustc_middle[cfbee9f1a0b252f]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[252fba113696aa73]::plumbing::QueryCtxt, false>
  36:     0x7f2d7b665304 - rustc_query_impl[252fba113696aa73]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  37:     0x7f2d7b22cd54 - rustc_hir_analysis[de820db48f542fb9]::check_crate
  38:     0x7f2d7b227972 - rustc_interface[dac25a6ec31f00eb]::passes::analysis
  39:     0x7f2d7b1f93ea - rustc_query_impl[252fba113696aa73]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[252fba113696aa73]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[cfbee9f1a0b252f]::query::erase::Erased<[u8; 1usize]>>
  40:     0x7f2d7b1f93d9 - <rustc_query_impl[252fba113696aa73]::query_impl::analysis::dynamic_query::{closure#2} as core[5a612027cd243909]::ops::function::FnOnce<(rustc_middle[cfbee9f1a0b252f]::ty::context::TyCtxt, ())>>::call_once
  41:     0x7f2d7b3ee984 - rustc_query_system[835e2ed124ae29cf]::query::plumbing::try_execute_query::<rustc_query_impl[252fba113696aa73]::DynamicConfig<rustc_query_system[835e2ed124ae29cf]::query::caches::SingleCache<rustc_middle[cfbee9f1a0b252f]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[252fba113696aa73]::plumbing::QueryCtxt, false>
  42:     0x7f2d7b3ee6f9 - rustc_query_impl[252fba113696aa73]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  43:     0x7f2d7aea9632 - <rustc_middle[cfbee9f1a0b252f]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[47b5c41fd5152b42]::run_compiler::{closure#1}::{closure#2}::{closure#6}, core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>>
  44:     0x7f2d7aea80b1 - rustc_span[56b754c3614a230e]::set_source_map::<core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>, rustc_interface[dac25a6ec31f00eb]::interface::run_compiler<core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>, rustc_driver_impl[47b5c41fd5152b42]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  45:     0x7f2d7aea2c90 - std[75110f2ce3cbb2c9]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[dac25a6ec31f00eb]::util::run_in_thread_with_globals<rustc_interface[dac25a6ec31f00eb]::interface::run_compiler<core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>, rustc_driver_impl[47b5c41fd5152b42]::run_compiler::{closure#1}>::{closure#0}, core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>>
  46:     0x7f2d7b56a9ee - <<std[75110f2ce3cbb2c9]::thread::Builder>::spawn_unchecked_<rustc_interface[dac25a6ec31f00eb]::util::run_in_thread_with_globals<rustc_interface[dac25a6ec31f00eb]::interface::run_compiler<core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>, rustc_driver_impl[47b5c41fd5152b42]::run_compiler::{closure#1}>::{closure#0}, core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5a612027cd243909]::result::Result<(), rustc_span[56b754c3614a230e]::ErrorGuaranteed>>::{closure#1} as core[5a612027cd243909]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  47:     0x7f2d78b8c395 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hfa37c25e0ad051b0
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/boxed.rs:2007:9
  48:     0x7f2d78b8c395 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h9486bed8ab2e65ad
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/alloc/src/boxed.rs:2007:9
  49:     0x7f2d78b8c395 - std::sys::unix::thread::Thread::new::thread_start::hd28b46dbf5673d17
                               at /rustc/79e9716c980570bfd1f666e3b16ac583f0168962/library/std/src/sys/unix/thread.rs:108:17
  50:     0x7f2d78a50609 - start_thread
  51:     0x7f2d78973133 - clone
  52:                0x0 - <unknown>

error: 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.74.0 (79e9716c9 2023-11-13) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `main::{constant#0}::_` is well-formed
#1 [check_mod_type_wf] checking that types are well-formed in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack

@iamanonymouscs iamanonymouscs 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 Nov 25, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 25, 2023
@saethlin
Copy link
Member

Oo this looks like #118098 but it's much smaller and doesn't need any features.

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 25, 2023
@saethlin
Copy link
Member

searched nightlies: from nightly-2023-01-01 to nightly-2023-11-20
regressed nightly: nightly-2023-09-14
searched commit range: d9c8274...8142a31
regressed commit: 76e59c7

bisected with cargo-bisect-rustc v0.6.7

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2023-01-01 --end=2023-11-20 --regress=ice 

cc @RalfJung

@gurry
Copy link
Contributor

gurry commented Nov 26, 2023

@rustbot claim

@RalfJung
Copy link
Member

RalfJung commented Nov 26, 2023

So that would be #115803 then. The panic originates here.

@RalfJung
Copy link
Member

using function pointers as const generic parameters is forbidden

After that error, something is still trying to create a valtree from a function pointer, it seems. I'd say that's a bug, my PR just turns it into an ICE -- but silencing the ICE does not fix the bug. Certain errors need to stop rustc from doing any further work with the faulty code.

Cc @rust-lang/project-const-generics

@oli-obk
Copy link
Contributor

oli-obk commented Nov 26, 2023

Can we turn it into a Constkind::Error instead of ICEing?

@RalfJung
Copy link
Member

I mean we could I guess, though it seems suspicious to me that we even call this function after the type checker already determined that this is not valid as a const generic.

@lcnr
Copy link
Contributor

lcnr commented Dec 1, 2023

We check the type of const parameters separately from when we compute them. Not doing so results in query cycles iirc 🤔 so it's probably best to delay_span_bug somewhere here instead of ICEing

@gurry gurry removed their assignment Dec 2, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 2, 2023
fix an ICE when a valtree failed to evaluate

Fixes rust-lang#118285

r? `@lcnr`
@bors bors closed this as completed in 4eede98 Dec 2, 2023
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. 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

Successfully merging a pull request may close this issue.

7 participants