Skip to content

Couldn't evaluate constant const with -Zpolymorphize=on #124192

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
Naserume opened this issue Apr 20, 2024 · 2 comments
Closed

Couldn't evaluate constant const with -Zpolymorphize=on #124192

Naserume opened this issue Apr 20, 2024 · 2 comments
Labels
-Zpolymorphize Unstable option: Polymorphization. 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

@Naserume
Copy link

Code

#![crate_type = "lib"]

pub fn demo_for_i32() {
    generic_impl::<bool>();
}

fn generic_impl<T>() {
    trait MagicTrait {
        const IS_BIG: bool;
    }
    impl<T> MagicTrait for T {
        const IS_BIG: bool = std::mem::size_of::<T>() > 10;
    }
    if T::IS_BIG {
        big_impl::<i32>();
    }  
}

fn big_impl<T>() {}

to run : rustc ./218ADF953E15EE53.rs -Zpolymorphize=on

Meta

rustc --version --verbose:

binary: rustc
commit-hash: f9b16149208c8a8a349c32813312716f6603eb6f
commit-date: 2024-04-19
host: x86_64-apple-darwin
release: 1.79.0-nightly
LLVM version: 18.1.4
Backtrace

error: internal compiler error: compiler/rustc_middle/src/mir/mod.rs:705:17: Couldn't evaluate constant const ::IS_BIG in mono Instance { def: Item(DefId(0:4 ~ 218ADF953E15EE53629956193E34723D019B7FF6E6049185C3303B99BE33D7C5[f8df]::generic_impl)), args: [T/#0] }

thread 'rustc' panicked at compiler/rustc_middle/src/mir/mod.rs:705:17:
Box
stack backtrace:
0: 0x10f0ac063 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h339f4af9bea4aeb1
1: 0x10f0f796b - core::fmt::write::h5a043ff03a3bd9b7
2: 0x10f0a212e - std::io::Write::write_fmt::hc9f26722443714d2
3: 0x10f0abe51 - std::sys_common::backtrace::print::hec15b0a1b187f43a
4: 0x10f0aeb49 - std::panicking::default_hook::{{closure}}::h77f4382f34966180
5: 0x10f0ae890 - std::panicking::default_hook::h95d46dff794c86a6
6: 0x117d26b3c - std[96c9014e9cc79c42]::panicking::update_hook::<alloc[b139a52cb69f6f02]::boxed::Box<rustc_driver_impl[aed2792d0255fb8]::install_ice_hook::{closure#0}>>::{closure#0}
7: 0x10f0af643 - std::panicking::rust_panic_with_hook::h19343a55bc932df0
8: 0x117d8e3ba - std[96c9014e9cc79c42]::panicking::begin_panic::<rustc_errors[2542ce93eb2c5131]::ExplicitBug>::{closure#0}
9: 0x117d87619 - std[96c9014e9cc79c42]::sys_common::backtrace::__rust_end_short_backtrace::<std[96c9014e9cc79c42]::panicking::begin_panic<rustc_errors[2542ce93eb2c5131]::ExplicitBug>::{closure#0}, !>
10: 0x11c4d34c9 - std[96c9014e9cc79c42]::panicking::begin_panic::<rustc_errors[2542ce93eb2c5131]::ExplicitBug>
11: 0x117da1c66 - <rustc_errors[2542ce93eb2c5131]::diagnostic::BugAbort as rustc_errors[2542ce93eb2c5131]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
12: 0x11888728e - rustc_middle[8b834d5ab41b7c4a]::util::bug::opt_span_bug_fmt::<rustc_span[3aebbb9d197be42]::span_encoding::Span>::{closure#0}
13: 0x118838177 - rustc_middle[8b834d5ab41b7c4a]::ty::context::tls::with_opt::<rustc_middle[8b834d5ab41b7c4a]::util::bug::opt_span_bug_fmt<rustc_span[3aebbb9d197be42]::span_encoding::Span>::{closure#0}, !>::{closure#0}
14: 0x118837be5 - rustc_middle[8b834d5ab41b7c4a]::ty::context::tls::with_context_opt::<rustc_middle[8b834d5ab41b7c4a]::ty::context::tls::with_opt<rustc_middle[8b834d5ab41b7c4a]::util::bug::opt_span_bug_fmt<rustc_span[3aebbb9d197be42]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
15: 0x11c59300b - rustc_middle[8b834d5ab41b7c4a]::util::bug::bug_fmt
16: 0x1187f371e - <rustc_middle[8b834d5ab41b7c4a]::mir::Body>::try_const_mono_switchint::{closure#0}
17: 0x1187f1584 - <rustc_middle[8b834d5ab41b7c4a]::mir::traversal::MonoReachable as core[48b09eea7890b3ea]::iter::traits::iterator::Iterator>::next
18: 0x118c4007c - rustc_monomorphize[d079dae585a9066d]::collector::collect_items_rec::{closure#0}
19: 0x118c3e2e7 - rustc_monomorphize[d079dae585a9066d]::collector::collect_items_rec
20: 0x118c3f917 - rustc_monomorphize[d079dae585a9066d]::collector::collect_items_rec
21: 0x118c34c7d - rustc_monomorphize[d079dae585a9066d]::partitioning::collect_and_partition_mono_items
22: 0x1191898d6 - rustc_query_impl[ab5369b0d00fe824]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab5369b0d00fe824]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b834d5ab41b7c4a]::query::erase::Erased<[u8; 24usize]>>
23: 0x1191545fe - <rustc_query_impl[ab5369b0d00fe824]::query_impl::collect_and_partition_mono_items::dynamic_query::{closure#2} as core[48b09eea7890b3ea]::ops::function::FnOnce<(rustc_middle[8b834d5ab41b7c4a]::ty::context::TyCtxt, ())>>::call_once
24: 0x118f700bd - rustc_query_system[aa282dbe93ac58a4]::query::plumbing::try_execute_query::<rustc_query_impl[ab5369b0d00fe824]::DynamicConfig<rustc_query_system[aa282dbe93ac58a4]::query::caches::SingleCache<rustc_middle[8b834d5ab41b7c4a]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[ab5369b0d00fe824]::plumbing::QueryCtxt, false>
25: 0x1191de5b3 - rustc_query_impl[ab5369b0d00fe824]::query_impl::collect_and_partition_mono_items::get_query_non_incr::__rust_end_short_backtrace
26: 0x117b768a0 - rustc_codegen_ssa[b745cd5c81484d7f]::back::symbol_export::exported_symbols_provider_local
27: 0x119186b43 - rustc_query_impl[ab5369b0d00fe824]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[ab5369b0d00fe824]::query_impl::exported_symbols::dynamic_query::{closure#2}::{closure#0}, rustc_middle[8b834d5ab41b7c4a]::query::erase::Erased<[u8; 16usize]>>
28: 0x119128e6e - <rustc_query_impl[ab5369b0d00fe824]::query_impl::exported_symbols::dynamic_query::{closure#2} as core[48b09eea7890b3ea]::ops::function::FnOnce<(rustc_middle[8b834d5ab41b7c4a]::ty::context::TyCtxt, rustc_span[3aebbb9d197be42]::def_id::CrateNum)>>::call_once
29: 0x119010105 - rustc_query_system[aa282dbe93ac58a4]::query::plumbing::try_execute_query::<rustc_query_impl[ab5369b0d00fe824]::DynamicConfig<rustc_query_system[aa282dbe93ac58a4]::query::caches::VecCache<rustc_span[3aebbb9d197be42]::def_id::LocalDefId, rustc_middle[8b834d5ab41b7c4a]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[ab5369b0d00fe824]::plumbing::QueryCtxt, false>
30: 0x1191de1b1 - rustc_query_impl[ab5369b0d00fe824]::query_impl::exported_symbols::get_query_non_incr::__rust_end_short_backtrace
31: 0x118609feb - rustc_middle[8b834d5ab41b7c4a]::query::plumbing::query_get_at::<rustc_query_system[aa282dbe93ac58a4]::query::caches::VecCache<rustc_span[3aebbb9d197be42]::def_id::CrateNum, rustc_middle[8b834d5ab41b7c4a]::query::erase::Erased<[u8; 16usize]>>>
32: 0x11869f227 - <rustc_metadata[4282c498f3a5aba6]::rmeta::encoder::EncodeContext>::encode_crate_root
33: 0x1186b3ae8 - rustc_metadata[4282c498f3a5aba6]::rmeta::encoder::encode_metadata
34: 0x1186c7b3f - rustc_metadata[4282c498f3a5aba6]::fs::encode_and_write_metadata
35: 0x1184f35a5 - rustc_interface[5475460b5e821a32]::passes::start_codegen
36: 0x1184fb99a - <rustc_interface[5475460b5e821a32]::queries::Queries>::codegen_and_build_linker
37: 0x117d2540e - rustc_interface[5475460b5e821a32]::interface::run_compiler::<core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>, rustc_driver_impl[aed2792d0255fb8]::run_compiler::{closure#0}>::{closure#1}
38: 0x117d1c7f1 - std[96c9014e9cc79c42]::sys_common::backtrace::_rust_begin_short_backtrace::<rustc_interface[5475460b5e821a32]::util::run_in_thread_with_globals<rustc_interface[5475460b5e821a32]::util::run_in_thread_pool_with_globals<rustc_interface[5475460b5e821a32]::interface::run_compiler<core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>, rustc_driver_impl[aed2792d0255fb8]::run_compiler::{closure#0}>::{closure#1}, core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>>::{closure#0}, core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>>
39: 0x117d2ea96 - <<std[96c9014e9cc79c42]::thread::Builder>::spawn_unchecked
<rustc_interface[5475460b5e821a32]::util::run_in_thread_with_globals<rustc_interface[5475460b5e821a32]::util::run_in_thread_pool_with_globals<rustc_interface[5475460b5e821a32]::interface::run_compiler<core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>, rustc_driver_impl[aed2792d0255fb8]::run_compiler::{closure#0}>::{closure#1}, core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>>::{closure#0}, core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[48b09eea7890b3ea]::result::Result<(), rustc_span[3aebbb9d197be42]::ErrorGuaranteed>>::{closure#2} as core[48b09eea7890b3ea]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
40: 0x10f0b8d0b - std::sys::pal::unix::thread::Thread::new::thread_start::h41e33ca082edcdc5
41: 0x7ff818270202 - __pthread_start

note: compiler flags: -Z polymorphize=on

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] collecting exported symbols for crate 0
end of query stack
error: aborting due to 1 previous error

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

matthiaskrgr commented Apr 20, 2024

duplicate of #123893 , even the exact same code lol

@Naserume
Copy link
Author

Omg you're right

@Naserume Naserume closed this as not planned Won't fix, can't repro, duplicate, stale Apr 20, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 20, 2024
@fmease fmease added the -Zpolymorphize Unstable option: Polymorphization. label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zpolymorphize Unstable option: Polymorphization. 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

No branches or pull requests

5 participants