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: enum variant discr was too generic to eval #135208

Open
matthiaskrgr opened this issue Jan 7, 2025 · 14 comments
Open

ICE: enum variant discr was too generic to eval #135208

matthiaskrgr opened this issue Jan 7, 2025 · 14 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-low Low priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

matthiaskrgr commented Jan 7, 2025

auto-reduced (treereduce-rust):

union Foo {
    a: str,
}

enum Bar {
    Boo = { let _: Option<Foo> = None; 0 },
}

Version information

rustc 1.86.0-nightly (fb546ee09 2025-01-07)
binary: rustc
commit-hash: fb546ee09b226bc4dd4b712d35a372d923c4fa54
commit-date: 2025-01-07
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.6

Possibly related line of code:

// Explicit `enum` discriminant values must const-evaluate successfully.
if let ty::VariantDiscr::Explicit(discr_def_id) = variant.discr {
match tcx.const_eval_poly(discr_def_id) {
Ok(_) => {}
Err(ErrorHandled::Reported(..)) => {}
Err(ErrorHandled::TooGeneric(sp)) => {
span_bug!(sp, "enum variant discr was too generic to eval")
}
}
}
}
check_where_clauses(wfcx, item.span, item.owner_id.def_id);

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

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.JPm8shtYqkkY/rustc_testrunner_tmpdir_reporting.ay3Lh8DeqrZK/mvce.rs:9:2
  |
9 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.JPm8shtYqkkY/rustc_testrunner_tmpdir_reporting.ay3Lh8DeqrZK/mvce.rs`

error[E0517]: attribute should be applied to a struct
 --> /tmp/icemaker_global_tempdir.JPm8shtYqkkY/rustc_testrunner_tmpdir_reporting.ay3Lh8DeqrZK/mvce.rs:1:8
  |
1 |   #[repr(simd)]
  |          ^^^^
2 | / union Foo {
3 | |     a: isize,
4 | |     b: (),
5 | | }
  | |_- not a struct

error: internal compiler error: compiler/rustc_hir_analysis/src/check/wfcheck.rs:1196:25: enum variant discr was too generic to eval


thread 'rustc' panicked at compiler/rustc_hir_analysis/src/check/wfcheck.rs:1196:25:
Box<dyn Any>
stack backtrace:
   0:     0x78406dce19ba - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h9bf89a0e5f11c1cf
   1:     0x78406e4135e6 - core::fmt::write::h761219e2be291c7a
   2:     0x78406f2d5991 - std::io::Write::write_fmt::h8032e22f9c3bd5b4
   3:     0x78406dce1812 - std::sys::backtrace::BacktraceLock::print::hebb5778cf40ee20f
   4:     0x78406dce3db7 - std::panicking::default_hook::{{closure}}::ha0fa1988f86f132d
   5:     0x78406dce3ba0 - std::panicking::default_hook::hc12d10b4cbb281ec
   6:     0x78406ce54a08 - std[a144ab5c1b85db5]::panicking::update_hook::<alloc[32a577d94c602890]::boxed::Box<rustc_driver_impl[c12604c6ccf9e768]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x78406dce4643 - std::panicking::rust_panic_with_hook::hf8ade0577c2f95bc
   8:     0x78406ce8cf31 - std[a144ab5c1b85db5]::panicking::begin_panic::<rustc_errors[f4fe76fe817796ae]::ExplicitBug>::{closure#0}
   9:     0x78406ce82116 - std[a144ab5c1b85db5]::sys::backtrace::__rust_end_short_backtrace::<std[a144ab5c1b85db5]::panicking::begin_panic<rustc_errors[f4fe76fe817796ae]::ExplicitBug>::{closure#0}, !>
  10:     0x78406ce82103 - std[a144ab5c1b85db5]::panicking::begin_panic::<rustc_errors[f4fe76fe817796ae]::ExplicitBug>
  11:     0x78406ce96e91 - <rustc_errors[f4fe76fe817796ae]::diagnostic::BugAbort as rustc_errors[f4fe76fe817796ae]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x78406d3e622c - <rustc_errors[f4fe76fe817796ae]::DiagCtxtHandle>::span_bug::<rustc_span[80f3292a29acebce]::span_encoding::Span, alloc[32a577d94c602890]::string::String>
  13:     0x78406d46b457 - rustc_middle[71fc52d0577df4e0]::util::bug::opt_span_bug_fmt::<rustc_span[80f3292a29acebce]::span_encoding::Span>::{closure#0}
  14:     0x78406d45044a - rustc_middle[71fc52d0577df4e0]::ty::context::tls::with_opt::<rustc_middle[71fc52d0577df4e0]::util::bug::opt_span_bug_fmt<rustc_span[80f3292a29acebce]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  15:     0x78406d4502db - rustc_middle[71fc52d0577df4e0]::ty::context::tls::with_context_opt::<rustc_middle[71fc52d0577df4e0]::ty::context::tls::with_opt<rustc_middle[71fc52d0577df4e0]::util::bug::opt_span_bug_fmt<rustc_span[80f3292a29acebce]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  16:     0x78406bed63c7 - rustc_middle[71fc52d0577df4e0]::util::bug::span_bug_fmt::<rustc_span[80f3292a29acebce]::span_encoding::Span>
  17:     0x78406eb32c5b - rustc_hir_analysis[58b1087c7a4e8d77]::check::wfcheck::check_type_defn
  18:     0x78406eb2c62e - rustc_hir_analysis[58b1087c7a4e8d77]::check::wfcheck::check_well_formed
  19:     0x78406eb2b363 - rustc_query_impl[c60017a6d5ec95c8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c60017a6d5ec95c8]::query_impl::check_well_formed::dynamic_query::{closure#2}::{closure#0}, rustc_middle[71fc52d0577df4e0]::query::erase::Erased<[u8; 1usize]>>
  20:     0x78406eb2ae05 - rustc_query_system[e4307e8df47736e2]::query::plumbing::try_execute_query::<rustc_query_impl[c60017a6d5ec95c8]::DynamicConfig<rustc_data_structures[228ab352de195f7]::vec_cache::VecCache<rustc_span[80f3292a29acebce]::def_id::LocalDefId, rustc_middle[71fc52d0577df4e0]::query::erase::Erased<[u8; 1usize]>, rustc_query_system[e4307e8df47736e2]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c60017a6d5ec95c8]::plumbing::QueryCtxt, false>
  21:     0x78406eb2a881 - rustc_query_impl[c60017a6d5ec95c8]::query_impl::check_well_formed::get_query_non_incr::__rust_end_short_backtrace
  22:     0x78406eb27cac - rustc_hir_analysis[58b1087c7a4e8d77]::check::wfcheck::check_mod_type_wf
  23:     0x78406eb27acb - rustc_query_impl[c60017a6d5ec95c8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c60017a6d5ec95c8]::query_impl::check_mod_type_wf::dynamic_query::{closure#2}::{closure#0}, rustc_middle[71fc52d0577df4e0]::query::erase::Erased<[u8; 1usize]>>
  24:     0x78406f392988 - rustc_query_system[e4307e8df47736e2]::query::plumbing::try_execute_query::<rustc_query_impl[c60017a6d5ec95c8]::DynamicConfig<rustc_query_system[e4307e8df47736e2]::query::caches::DefaultCache<rustc_span[80f3292a29acebce]::def_id::LocalModDefId, rustc_middle[71fc52d0577df4e0]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[c60017a6d5ec95c8]::plumbing::QueryCtxt, false>
  25:     0x78406f392730 - rustc_query_impl[c60017a6d5ec95c8]::query_impl::check_mod_type_wf::get_query_non_incr::__rust_end_short_backtrace
  26:     0x78406e778d78 - rustc_hir_analysis[58b1087c7a4e8d77]::check_crate
  27:     0x78406e6ba668 - rustc_interface[26e69c7fcb6d2c01]::passes::run_required_analyses
  28:     0x78406f2d981e - rustc_interface[26e69c7fcb6d2c01]::passes::analysis
  29:     0x78406f2d97ef - rustc_query_impl[c60017a6d5ec95c8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c60017a6d5ec95c8]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[71fc52d0577df4e0]::query::erase::Erased<[u8; 0usize]>>
  30:     0x78406f3b7695 - rustc_query_system[e4307e8df47736e2]::query::plumbing::try_execute_query::<rustc_query_impl[c60017a6d5ec95c8]::DynamicConfig<rustc_query_system[e4307e8df47736e2]::query::caches::SingleCache<rustc_middle[71fc52d0577df4e0]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[c60017a6d5ec95c8]::plumbing::QueryCtxt, false>
  31:     0x78406f3b73ce - rustc_query_impl[c60017a6d5ec95c8]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  32:     0x78406f30431e - rustc_interface[26e69c7fcb6d2c01]::passes::create_and_enter_global_ctxt::<core[465b72dbeda08b19]::option::Option<rustc_interface[26e69c7fcb6d2c01]::queries::Linker>, rustc_driver_impl[c12604c6ccf9e768]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  33:     0x78406f377724 - rustc_interface[26e69c7fcb6d2c01]::interface::run_compiler::<(), rustc_driver_impl[c12604c6ccf9e768]::run_compiler::{closure#0}>::{closure#1}
  34:     0x78406f1f8007 - std[a144ab5c1b85db5]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[26e69c7fcb6d2c01]::util::run_in_thread_with_globals<rustc_interface[26e69c7fcb6d2c01]::util::run_in_thread_pool_with_globals<rustc_interface[26e69c7fcb6d2c01]::interface::run_compiler<(), rustc_driver_impl[c12604c6ccf9e768]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  35:     0x78406f1f84a4 - <<std[a144ab5c1b85db5]::thread::Builder>::spawn_unchecked_<rustc_interface[26e69c7fcb6d2c01]::util::run_in_thread_with_globals<rustc_interface[26e69c7fcb6d2c01]::util::run_in_thread_pool_with_globals<rustc_interface[26e69c7fcb6d2c01]::interface::run_compiler<(), rustc_driver_impl[c12604c6ccf9e768]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[465b72dbeda08b19]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  36:     0x78406f1f9a6f - std::sys::pal::unix::thread::Thread::new::thread_start::hf3e31ce7c291fa9b
  37:     0x7840696a339d - <unknown>
  38:     0x78406972849c - <unknown>
  39:                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.86.0-nightly (fb546ee09 2025-01-07) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [check_well_formed] checking that `Bar` 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
error: aborting due to 3 previous errors

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

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

bisects to #133610

@theemathas
Copy link
Contributor

Another variation:

#[repr(simd)]
enum Foo {
    A,
}

enum Bar {
    Boo = { Foo::A; 1 },
}

@rustbot label +regression-from-stable-to-nightly

@rustbot rustbot added regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 7, 2025
@BoxyUwU BoxyUwU added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 7, 2025
@workingjubilee
Copy link
Member

repr(simd) is an implementation detail that has no defined effect for unions or enums.

@workingjubilee
Copy link
Member

This is only reached by misusing internal APIs.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jan 7, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Jan 7, 2025

@workingjubilee in any case, this still should not ICE, no? Shouldn't rustc just report an error then gracefully exit?

EDIT: if this was only ICEing on repr_simd, I would agree with closing this, but apparently that's not actually required as reported in #135208 (comment)...

@matthiaskrgr
Copy link
Member Author

I agree, maybe we can do better error-tainting and not run into an ICE later on..

@jieyouxu jieyouxu reopened this Jan 7, 2025
@jieyouxu

This comment has been minimized.

@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jan 7, 2025
@lukas-code
Copy link
Member

This is only reached by misusing internal APIs.

This is also reachable without repr(simd), any type with a layout error will do:

union Foo {
    a: str,
}

enum Bar {
    Boo = { let _: Option<Foo> = None; 0 },
}

@workingjubilee
Copy link
Member

oh, a reduction that removes the usage of the internal API! brilliant.

@Noratrieb
Copy link
Member

@matthiaskrgr when reducing issues, please remove such internal unnecessary features when needed. treereduce is a great tool, but it is not a complete substitute for human guided reductions.

@matthiaskrgr
Copy link
Member Author

of course not!

Please note that on the original code, the ICE is no longer reproducible if you just remove the attribute, so it would have never been found without it.

@matthiaskrgr
Copy link
Member Author

I think point "internal api" is also easily dismissed because we never opted into said feature by declaring #[feature(repr_simd)] and rustc never issued a

error[E0658]: SIMD types are experimental and possibly buggy
 --> f.rs:1:1
  |
1 | #[repr(simd)]
  | ^^^^^^^^^^^^^
  |
  = note: see issue #27731 <https://github.com/rust-lang/rust/issues/27731> for more information
  = help: add `#![feature(repr_simd)]` to the crate attributes to enable
  = note: this compiler was built on 2025-01-06; consider upgrading it if it is out of date

which should be the bare minimum to tell the user that they may be going off the rails.

@workingjubilee
Copy link
Member

@matthiaskrgr If you're so concerned about the feature gate handling in rustc then I await your PR.

@Noratrieb Noratrieb removed the P-low Low priority label Jan 7, 2025
@BoxyUwU BoxyUwU added the P-low Low priority label Jan 7, 2025
@BoxyUwU
Copy link
Member

BoxyUwU commented Jan 7, 2025

re-triaging as P-low since it still has good error messages and it is a regression

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 8, 2025
…rrors

warn about broken simd not only on structs but also enums and unions when we didn't opt in to it

addresses rust-lang#135208 (comment)

r? `@Noratrieb`
jhpratt added a commit to jhpratt/rust that referenced this issue Jan 8, 2025
…rrors

warn about broken simd not only on structs but also enums and unions when we didn't opt in to it

addresses rust-lang#135208 (comment)

r? ``@Noratrieb``
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 8, 2025
Rollup merge of rust-lang#135219 - matthiaskrgr:simd'nt, r=compiler-errors

warn about broken simd not only on structs but also enums and unions when we didn't opt in to it

addresses rust-lang#135208 (comment)

r? ``@Noratrieb``
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) ❄️ P-low Low priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants