rust-lang / rust

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

ICE: interpret const eval failure of `Unevaluated(UnevaluatedConst` #130687

Open matthiaskrgr opened 1 month ago

matthiaskrgr commented 1 month ago

snippet:

pub struct Data([u8; usize::MAX >> 16]);
const _: &'static Data = &Data([0; usize::MAX >> 16]);

Version information

rustc 1.83.0-nightly (55043f067 2024-09-22)
binary: rustc
commit-hash: 55043f067dcf7067e7c6ebccf3639af94ff57bda
commit-date: 2024-09-22
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.0

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

Program output

``` error[E0601]: `main` function not found in crate `mvce` --> /tmp/icemaker_global_tempdir.uajd7BjF457F/rustc_testrunner_tmpdir_reporting.GJfRmJzXgPMl/mvce.rs:2:55 | 2 | const _: &'static Data = &Data([0; usize::MAX >> 16]); | ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.uajd7BjF457F/rustc_testrunner_tmpdir_reporting.GJfRmJzXgPMl/mvce.rs` error[E0080]: evaluation of constant value failed --> /tmp/icemaker_global_tempdir.uajd7BjF457F/rustc_testrunner_tmpdir_reporting.GJfRmJzXgPMl/mvce.rs:2:32 | 2 | const _: &'static Data = &Data([0; usize::MAX >> 16]); | ^^^^^^^^^^^^^^^^^^^^^ tried to allocate more memory than available to compiler error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:586:33: interpret const eval failure of Unevaluated(UnevaluatedConst { def: DefId(0:7 ~ mvce[dab4]::_), args: [], promoted: Some(promoted[0]) }, &'{erased} Data) which is not in required_consts --> /tmp/icemaker_global_tempdir.uajd7BjF457F/rustc_testrunner_tmpdir_reporting.GJfRmJzXgPMl/mvce.rs:2:26 | 2 | const _: &'static Data = &Data([0; usize::MAX >> 16]); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:586:33: Box stack backtrace: 0: 0x7c179568af1a - ::fmt::hd890a259e842de86 1: 0x7c1795e03666 - core::fmt::write::ha27dfc921a37964e 2: 0x7c1796d02333 - std::io::Write::write_fmt::h70c8a0cc59cad0a8 3: 0x7c179568ad72 - std::sys::backtrace::BacktraceLock::print::h3013cc5c3ae4074f 4: 0x7c179568d4f1 - std::panicking::default_hook::{{closure}}::h9e5c041fcf401891 5: 0x7c179568d324 - std::panicking::default_hook::h788b5d87547559ac 6: 0x7c179478495f - std[232e32126cf29c33]::panicking::update_hook::>::{closure#0} 7: 0x7c179568dc08 - std::panicking::rust_panic_with_hook::hb1c7ebf17e599033 8: 0x7c17947bf061 - std[232e32126cf29c33]::panicking::begin_panic::::{closure#0} 9: 0x7c17947b2106 - std[232e32126cf29c33]::sys::backtrace::__rust_end_short_backtrace::::{closure#0}, !> 10: 0x7c17947ad5d9 - std[232e32126cf29c33]::panicking::begin_panic:: 11: 0x7c17947c88b1 - ::emit_producing_guarantee 12: 0x7c17946da6fd - ::span_bug:: 13: 0x7c17946f60d8 - rustc_middle[2422fc0a2a72bca0]::util::bug::opt_span_bug_fmt::::{closure#0} 14: 0x7c17946f638a - rustc_middle[2422fc0a2a72bca0]::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0} 15: 0x7c17946ea51b - rustc_middle[2422fc0a2a72bca0]::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !> 16: 0x7c179367c547 - rustc_middle[2422fc0a2a72bca0]::util::bug::span_bug_fmt:: 17: 0x7c17968eb5b4 - >::eval_rvalue_into_place 18: 0x7c17936fadd2 - rustc_const_eval[52bfe85ce8cf4586]::const_eval::eval_queries::eval_to_allocation_raw_provider 19: 0x7c1796501bb6 - rustc_query_impl[68ff1bc69f23602]::plumbing::__rust_begin_short_backtrace::> 20: 0x7c1796502bef - )>>::call_once 21: 0x7c1796502b71 - , rustc_middle[2422fc0a2a72bca0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt>::{closure#2}::{closure#2} as core[7ac7550d2f2632cb]::ops::function::FnOnce<((rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt, rustc_query_impl[68ff1bc69f23602]::DynamicConfig, rustc_middle[2422fc0a2a72bca0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>), rustc_middle[2422fc0a2a72bca0]::ty::ParamEnvAnd)>>::call_once 22: 0x7c17965181ae - rustc_query_system[67db78f99bfebbdc]::query::plumbing::try_execute_query::, rustc_middle[2422fc0a2a72bca0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt, true> 23: 0x7c17965176b6 - rustc_query_impl[68ff1bc69f23602]::query_impl::eval_to_allocation_raw::get_query_incr::__rust_end_short_backtrace 24: 0x7c1796502e2e - rustc_const_eval[52bfe85ce8cf4586]::const_eval::eval_queries::eval_to_const_value_raw_provider 25: 0x7c1796502c36 - rustc_query_impl[68ff1bc69f23602]::plumbing::__rust_begin_short_backtrace::> 26: 0x7c1796502baf - )>>::call_once 27: 0x7c1796502b71 - , rustc_middle[2422fc0a2a72bca0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt>::{closure#2}::{closure#2} as core[7ac7550d2f2632cb]::ops::function::FnOnce<((rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt, rustc_query_impl[68ff1bc69f23602]::DynamicConfig, rustc_middle[2422fc0a2a72bca0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>), rustc_middle[2422fc0a2a72bca0]::ty::ParamEnvAnd)>>::call_once 28: 0x7c17965181ae - rustc_query_system[67db78f99bfebbdc]::query::plumbing::try_execute_query::, rustc_middle[2422fc0a2a72bca0]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt, true> 29: 0x7c1796517a4c - rustc_query_impl[68ff1bc69f23602]::query_impl::eval_to_const_value_raw::get_query_incr::__rust_end_short_backtrace 30: 0x7c1796197c3d - ::par_body_owners::::{closure#0} 31: 0x7c17961954d2 - rustc_hir_analysis[2606297559afc5bb]::check_crate 32: 0x7c1796191e05 - rustc_interface[3feab42be5996c7]::passes::run_required_analyses 33: 0x7c1796a2a29e - rustc_interface[3feab42be5996c7]::passes::analysis 34: 0x7c1796a2a271 - rustc_query_impl[68ff1bc69f23602]::plumbing::__rust_begin_short_backtrace::> 35: 0x7c1796f261c1 - rustc_query_system[67db78f99bfebbdc]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[68ff1bc69f23602]::plumbing::QueryCtxt, true> 36: 0x7c1796f25e7a - rustc_query_impl[68ff1bc69f23602]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace 37: 0x7c1796b399de - rustc_interface[3feab42be5996c7]::interface::run_compiler::, rustc_driver_impl[b1c9e4000593b067]::run_compiler::{closure#0}>::{closure#1} 38: 0x7c1796bc4990 - std[232e32126cf29c33]::sys::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[b1c9e4000593b067]::run_compiler::{closure#0}>::{closure#1}, core[7ac7550d2f2632cb]::result::Result<(), rustc_span[4e9173d9ab4d4daa]::ErrorGuaranteed>>::{closure#0}, core[7ac7550d2f2632cb]::result::Result<(), rustc_span[4e9173d9ab4d4daa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7ac7550d2f2632cb]::result::Result<(), rustc_span[4e9173d9ab4d4daa]::ErrorGuaranteed>> 39: 0x7c1796bc4ffa - <::spawn_unchecked_, rustc_driver_impl[b1c9e4000593b067]::run_compiler::{closure#0}>::{closure#1}, core[7ac7550d2f2632cb]::result::Result<(), rustc_span[4e9173d9ab4d4daa]::ErrorGuaranteed>>::{closure#0}, core[7ac7550d2f2632cb]::result::Result<(), rustc_span[4e9173d9ab4d4daa]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[7ac7550d2f2632cb]::result::Result<(), rustc_span[4e9173d9ab4d4daa]::ErrorGuaranteed>>::{closure#1} as core[7ac7550d2f2632cb]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} 40: 0x7c1796bc53eb - std::sys::pal::unix::thread::Thread::new::thread_start::h6e4c0266f3b27cf2 41: 0x7c179825939d - 42: 0x7c17982de49c - 43: 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.83.0-nightly (55043f067 2024-09-22) 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: #0 [eval_to_allocation_raw] const-evaluating + checking `_` #1 [eval_to_const_value_raw] simplifying constant for the type system `_` end of query stack error: aborting due to 3 previous errors Some errors have detailed explanations: E0080, E0601. For more information about an error, try `rustc --explain E0080`. ```

matthiaskrgr commented 1 month ago

Regression in #127546 cc @workingjubilee

saethlin commented 1 month ago

Nope. That PR just changed the size at which things become problematic, which should tell you that the bisection is wrong. If you tweak the constants just a little bit:

pub struct Data([u8; usize::MAX >> 17]);
const _: &'static Data = &Data([0; usize::MAX >> 17]);

This bisects instead to https://github.com/rust-lang/rust/pull/121557

workingjubilee commented 1 month ago

is "the compiler OOMs when you try to make it OOM" really a "regression"?

workingjubilee commented 1 month ago

answer after some discussion: possibly, if it was supposed to stop compilation when it detected it was going to OOM if it continued!

RalfJung commented 1 day ago

Ah, exciting... there is indeed a way that all constants can fail to evaluate, even those that have been promoted because they seem "infallible".