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: interpret const eval failure of Unevaluated(UnevaluatedConst ... which is not in required_consts #124348

Open
matthiaskrgr opened this issue Apr 24, 2024 · 5 comments · May be fixed by #124516
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-bug-has-test Status: A `known-bug` test has been added for this bug. 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):

enum Eek {
    TheConst,
    UnusedByTheConst(Sum),
}

const EEK_ZERO: &[Eek] = &[];
original code

original:

// rust-lang/rust#62614: we want to allow matching on constants of types that
// have non-structural-match variants, *if* the constant itself does not use
// any such variant.

// NOTE: for now, deliberately leaving the lint `indirect_structural_match` set
// to its default, so that we will not issue a diangostic even if
// rust-lang/rust#62614 remains an open issue.

//@ run-pass

struct Sum(&'a &'a NoDerive);

impl PartialEq for Sum {
    fn eq(&self, other: &Self) -> bool { self.0 + self.1 == other.0 + other.1 }
}

impl Eq for Sum { }

#[derive(PartialEq, Eq)]
enum Eek {
    TheConst,
    UnusedByTheConst(Sum)
}

const THE_CONST: Eek = Eek::TheConst;
const SUM_THREE: Eek = Eek::UnusedByTheConst(Sum(3,0));

const EEK_ZERO: &[Eek] = &[];
const EEK_ONE: &[StructuralPartialEq] = &[THE_CONST];

pub fn main() {
    match Eek::UnusedByTheConst(Sum(1,2)) {
        ref sum if sum == &SUM_THREE => { println!("Hello 0"); }
        _ => { println!("Gbye"); }
    }

    match Eek::TheConst {
        THE_CONST => { println!("Hello 1"); }
        _ => { println!("Gbye"); }
    }


    match & &Eek::TheConst {
        & & THE_CONST => { println!("Hello 2"); }
        _ => { println!("Gbye"); }
    }

    match & & &[][..] {
        & & EEK_ZERO => { println!("Hello 3"); }
        & & EEK_ONE => { println!("Gbye"); }
        _ => { println!("Gbye"); }
    }

    match & & &[Eek::TheConst][..] {
        & & EEK_ZERO => { println!("Gby"); }
        & & EEK_ONE => { println!("Hello 4"); }
        _  { println!("Gbye"); }
    }
}

Version information

rustc 1.79.0-nightly (7bb4f0889 2024-04-24)
binary: rustc
commit-hash: 7bb4f0889e8b133c5b03c46f31f2ae6432c00219
commit-date: 2024-04-24
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

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

Program output

error[E0412]: cannot find type `Sum` in this scope
 --> /tmp/icemaker_global_tempdir.g0OXoW02g0sV/rustc_testrunner_tmpdir_reporting.4mOsaGXo4NAR/mvce.rs:3:22
  |
3 |     UnusedByTheConst(Sum),
  |                      ^^^ not found in this scope
  |
help: consider importing this trait
  |
1 + use std::iter::Sum;
  |

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.g0OXoW02g0sV/rustc_testrunner_tmpdir_reporting.4mOsaGXo4NAR/mvce.rs:6:30
  |
6 | const EEK_ZERO: &[Eek] = &[];
  |                              ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.g0OXoW02g0sV/rustc_testrunner_tmpdir_reporting.4mOsaGXo4NAR/mvce.rs`

error: internal compiler error: compiler/rustc_const_eval/src/interpret/eval_context.rs:1184:21: interpret const eval failure of Unevaluated(UnevaluatedConst { def: DefId(0:9 ~ mvce[ac98]::EEK_ZERO), args: [], promoted: Some(promoted[0]) }, &'{erased} [Eek; 0_usize]) which is not in required_consts

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/eval_context.rs:1184:21:
Box<dyn Any>
stack backtrace:
   0:     0x7f9cb8b4e145 - std::backtrace_rs::backtrace::libunwind::trace::h86d426b17d4e2e3d
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7f9cb8b4e145 - std::backtrace_rs::backtrace::trace_unsynchronized::h8c0ef1d148b9d940
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f9cb8b4e145 - std::sys_common::backtrace::_print_fmt::he2abce7aa62cdc3a
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7f9cb8b4e145 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0c9241533158777f
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f9cb8b9d21b - core::fmt::rt::Argument::fmt::h733dbde17a4a7d04
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/core/src/fmt/rt.rs:165:63
   5:     0x7f9cb8b9d21b - core::fmt::write::h03896a7fdcd4b82f
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/core/src/fmt/mod.rs:1157:21
   6:     0x7f9cb8b42d4f - std::io::Write::write_fmt::hd74e7c0305df2660
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/io/mod.rs:1832:15
   7:     0x7f9cb8b4df1e - std::sys_common::backtrace::_print::hea8c9c28ab87b1b7
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f9cb8b4df1e - std::sys_common::backtrace::print::hd4bb5623fa4b8de6
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f9cb8b50889 - std::panicking::default_hook::{{closure}}::h4623b55631f16943
  10:     0x7f9cb8b505cd - std::panicking::default_hook::he5d3fa1d7e671103
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/panicking.rs:298:9
  11:     0x7f9cb54456ab - std[73cef507c0358b10]::panicking::update_hook::<alloc[3ec83808c4b91c16]::boxed::Box<rustc_driver_impl[2d410f393cf62b06]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7f9cb8b50f86 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h8ef97572a456b9c7
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/alloc/src/boxed.rs:2036:9
  13:     0x7f9cb8b50f86 - std::panicking::rust_panic_with_hook::h1e2384e63ce90283
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/panicking.rs:799:13
  14:     0x7f9cb5475814 - std[73cef507c0358b10]::panicking::begin_panic::<rustc_errors[bc43925ba4bc70ce]::ExplicitBug>::{closure#0}
  15:     0x7f9cb5472376 - std[73cef507c0358b10]::sys_common::backtrace::__rust_end_short_backtrace::<std[73cef507c0358b10]::panicking::begin_panic<rustc_errors[bc43925ba4bc70ce]::ExplicitBug>::{closure#0}, !>
  16:     0x7f9cb546d976 - std[73cef507c0358b10]::panicking::begin_panic::<rustc_errors[bc43925ba4bc70ce]::ExplicitBug>
  17:     0x7f9cb547ec51 - <rustc_errors[bc43925ba4bc70ce]::diagnostic::BugAbort as rustc_errors[bc43925ba4bc70ce]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  18:     0x7f9cb592a79c - rustc_middle[65b49a3b5d6c0d49]::util::bug::opt_span_bug_fmt::<rustc_span[ec1f1d58828cad2c]::span_encoding::Span>::{closure#0}
  19:     0x7f9cb591212a - rustc_middle[65b49a3b5d6c0d49]::ty::context::tls::with_opt::<rustc_middle[65b49a3b5d6c0d49]::util::bug::opt_span_bug_fmt<rustc_span[ec1f1d58828cad2c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  20:     0x7f9cb5911fab - rustc_middle[65b49a3b5d6c0d49]::ty::context::tls::with_context_opt::<rustc_middle[65b49a3b5d6c0d49]::ty::context::tls::with_opt<rustc_middle[65b49a3b5d6c0d49]::util::bug::opt_span_bug_fmt<rustc_span[ec1f1d58828cad2c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  21:     0x7f9cb35581a0 - rustc_middle[65b49a3b5d6c0d49]::util::bug::bug_fmt
  22:     0x7f9cb738877c - <rustc_const_eval[fedc7aa5d50c96b6]::interpret::eval_context::InterpCx<rustc_const_eval[fedc7aa5d50c96b6]::const_eval::machine::CompileTimeInterpreter>>::eval_rvalue_into_place
  23:     0x7f9cb47ef0a8 - rustc_const_eval[fedc7aa5d50c96b6]::const_eval::eval_queries::eval_to_allocation_raw_provider
  24:     0x7f9cb705b776 - rustc_query_impl[e8a6f5b0469e51af]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e8a6f5b0469e51af]::query_impl::eval_to_allocation_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 24usize]>>
  25:     0x7f9cb705af99 - rustc_query_system[ccb87b148b9f71e3]::query::plumbing::try_execute_query::<rustc_query_impl[e8a6f5b0469e51af]::DynamicConfig<rustc_query_system[ccb87b148b9f71e3]::query::caches::DefaultCache<rustc_middle[65b49a3b5d6c0d49]::ty::ParamEnvAnd<rustc_middle[65b49a3b5d6c0d49]::mir::interpret::GlobalId>, rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[e8a6f5b0469e51af]::plumbing::QueryCtxt, false>
  26:     0x7f9cb705ab6c - rustc_query_impl[e8a6f5b0469e51af]::query_impl::eval_to_allocation_raw::get_query_non_incr::__rust_end_short_backtrace
  27:     0x7f9cb705a702 - rustc_middle[65b49a3b5d6c0d49]::query::plumbing::query_get_at::<rustc_query_system[ccb87b148b9f71e3]::query::caches::DefaultCache<rustc_middle[65b49a3b5d6c0d49]::ty::ParamEnvAnd<rustc_middle[65b49a3b5d6c0d49]::mir::interpret::GlobalId>, rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 24usize]>>>
  28:     0x7f9cb7058afc - rustc_const_eval[fedc7aa5d50c96b6]::const_eval::eval_queries::eval_to_const_value_raw_provider
  29:     0x7f9cb7058a76 - rustc_query_impl[e8a6f5b0469e51af]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e8a6f5b0469e51af]::query_impl::eval_to_const_value_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 24usize]>>
  30:     0x7f9cb705af5c - rustc_query_system[ccb87b148b9f71e3]::query::plumbing::try_execute_query::<rustc_query_impl[e8a6f5b0469e51af]::DynamicConfig<rustc_query_system[ccb87b148b9f71e3]::query::caches::DefaultCache<rustc_middle[65b49a3b5d6c0d49]::ty::ParamEnvAnd<rustc_middle[65b49a3b5d6c0d49]::mir::interpret::GlobalId>, rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[e8a6f5b0469e51af]::plumbing::QueryCtxt, false>
  31:     0x7f9cb705aa6c - rustc_query_impl[e8a6f5b0469e51af]::query_impl::eval_to_const_value_raw::get_query_non_incr::__rust_end_short_backtrace
  32:     0x7f9cb6be74d1 - <rustc_middle[65b49a3b5d6c0d49]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[4525919e9da128a7]::check_crate::{closure#3}>::{closure#0}
  33:     0x7f9cb6be5b74 - rustc_hir_analysis[4525919e9da128a7]::check_crate
  34:     0x7f9cb6bef507 - rustc_interface[b73225351c325ab5]::passes::analysis
  35:     0x7f9cb6bef055 - rustc_query_impl[e8a6f5b0469e51af]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[e8a6f5b0469e51af]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 1usize]>>
  36:     0x7f9cb75be665 - rustc_query_system[ccb87b148b9f71e3]::query::plumbing::try_execute_query::<rustc_query_impl[e8a6f5b0469e51af]::DynamicConfig<rustc_query_system[ccb87b148b9f71e3]::query::caches::SingleCache<rustc_middle[65b49a3b5d6c0d49]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[e8a6f5b0469e51af]::plumbing::QueryCtxt, false>
  37:     0x7f9cb75be3c9 - rustc_query_impl[e8a6f5b0469e51af]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  38:     0x7f9cb7445993 - rustc_interface[b73225351c325ab5]::interface::run_compiler::<core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>, rustc_driver_impl[2d410f393cf62b06]::run_compiler::{closure#0}>::{closure#1}
  39:     0x7f9cb742f8e7 - std[73cef507c0358b10]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[b73225351c325ab5]::util::run_in_thread_with_globals<rustc_interface[b73225351c325ab5]::util::run_in_thread_pool_with_globals<rustc_interface[b73225351c325ab5]::interface::run_compiler<core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>, rustc_driver_impl[2d410f393cf62b06]::run_compiler::{closure#0}>::{closure#1}, core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>>::{closure#0}, core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>>
  40:     0x7f9cb742f6aa - <<std[73cef507c0358b10]::thread::Builder>::spawn_unchecked_<rustc_interface[b73225351c325ab5]::util::run_in_thread_with_globals<rustc_interface[b73225351c325ab5]::util::run_in_thread_pool_with_globals<rustc_interface[b73225351c325ab5]::interface::run_compiler<core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>, rustc_driver_impl[2d410f393cf62b06]::run_compiler::{closure#0}>::{closure#1}, core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>>::{closure#0}, core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[dad89120088e7e02]::result::Result<(), rustc_span[ec1f1d58828cad2c]::ErrorGuaranteed>>::{closure#2} as core[dad89120088e7e02]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  41:     0x7f9cb8b5ae1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3679caeb60ab03c2
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/alloc/src/boxed.rs:2022:9
  42:     0x7f9cb8b5ae1b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h7e27b57c37e0ef1f
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/alloc/src/boxed.rs:2022:9
  43:     0x7f9cb8b5ae1b - std::sys::pal::unix::thread::Thread::new::thread_start::he8797429d1c20e6e
                               at /rustc/7bb4f0889e8b133c5b03c46f31f2ae6432c00219/library/std/src/sys/pal/unix/thread.rs:108:17
  44:     0x7f9cb22a955a - <unknown>
  45:     0x7f9cb2326a3c - <unknown>
  46:                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.79.0-nightly (7bb4f0889 2024-04-24) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [eval_to_allocation_raw] const-evaluating + checking `EEK_ZERO`
#1 [eval_to_const_value_raw] simplifying constant for the type system `EEK_ZERO`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0412, E0601.
For more information about an error, try `rustc --explain E0412`.

@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 Apr 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 24, 2024
@matthiaskrgr
Copy link
Member Author

#121557 cc @RalfJung

@matthiaskrgr matthiaskrgr changed the title ICE: interpret const eval failure of Unevaluated(UnevaluatedConst ICE: interpret const eval failure of Unevaluated(UnevaluatedConst ... which is not in required_consts Apr 24, 2024
@RalfJung
Copy link
Member

Caused by running the interpreter on code that doesn't even pass name resolution. Not sure where to fix this, but probably not in the interpreter.^^

Cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Apr 26, 2024

this is a promoted failing to compile because it gets the layout of this broken type, which gives us back an ErrorGuaranteed. I'm certain we can prevent const eval from running by checking such layouts earlier in the MIR pipeline, but the fix isn't clear to me yet.

@RalfJung
Copy link
Member

The issue is that in the sanity check here we only know it's an ErrorHandled::Reported, we don't know whether it was a typeck error on a const-eval error. So we can't really distinguish these cases.

If this is a LayoutError::ReferencesError, we could probably fix it by tweaking the error handling here. But there probably are similar cases where a promoted fails to evaluate due to a SizeOverflow and then we have to report the error somewhere.

The only option I see right now is to add another variant to ErrorHandled (or a flag in ErrorHandled::Reported) to track whether this was a failure inside the constant itself or a failure in something the constant referenced. But this distinction isn't always very clear anyway... it would basically have to be "is this an error that can occur even for supposedly infallible operations like &[]", i.e., match exactly the usecase of the const-eval / promoted sanity check. Which is not great.

@oli-obk
Copy link
Contributor

oli-obk commented Apr 26, 2024

We already got the tainted_by_errors flag that we can reuse for that

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: A `known-bug` test has been added for this bug. label Apr 27, 2024
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) ❄️ needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. S-bug-has-test Status: A `known-bug` test has been added for this bug. 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.

4 participants