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

I found a bug😁 #121771

Closed
jakelsen opened this issue Feb 29, 2024 · 2 comments
Closed

I found a bug😁 #121771

jakelsen opened this issue Feb 29, 2024 · 2 comments
Labels
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

@jakelsen
Copy link

Code

#![feature(core_intrinsics)]
#![allow(internal_features)]
#![feature(non_exhaustive_omitted_patterns_lint)]

use core::intrinsics;

pub trait N: Copy + std::ops::Add {
    fn from(num: u128) -> Self;
    fn into(self) -> u128;
}

impl N for u8 {
    fn from(num: u128) -> Self {
        num as u8
    }

    fn into(self) -> u128 {
        self as u128
    }
}

pub fn add<T>(a: u128, b: u128)
where
    T: N,
{
    let result = intrinsics::add_with_overflow(T::from(a), T::from(b));
}

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (ef324565d 2024-02-27)
binary: rustc
commit-hash: ef324565d071c6d7e2477a195648549e33d6a465
commit-date: 2024-02-27
host: x86_64-apple-darwin
release: 1.78.0-nightly
LLVM version: 18.1.0

Error output

thread 'rustc' panicked at compiler/rustc_const_eval/src/transform/validate.rs:88:25:
broken MIR in Item(DefId(0:10 ~ henvm[85e6]::add)) (after phase change to runtime-optimized) at bb2[0]:
Cannot perform checked arithmetic on type T/#0
Backtrace

stack backtrace:
   0:        0x10ebee745 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h41b9dcd84c0d46ef
   1:        0x10ec3bf0b - core::fmt::write::h4fe2ff48e95394fd
   2:        0x10ebe46ae - std::io::Write::write_fmt::ha630f35774432590
   3:        0x10ebee501 - std::sys_common::backtrace::print::h8d18f6db311db8c1
   4:        0x10ebf1569 - std::panicking::default_hook::{{closure}}::h2a81b4f370f7ad04
   5:        0x10ebf12d6 - std::panicking::default_hook::h3ff7e946bc95e5e8
   6:        0x11d0d064f - std[38e54a1d943a7f58]::panicking::update_hook::<alloc[358a2b952a6a0aef]::boxed::Box<rustc_driver_impl[963ac894dc08b358]::install_ice_hook::{closure#0}>>::{closure#0}
   7:        0x10ebf208b - std::panicking::rust_panic_with_hook::h3fef8e986af65813
   8:        0x10ebf19c4 - std::panicking::begin_panic_handler::{{closure}}::h8e831b49d5c6f40d
   9:        0x10ebeec39 - std::sys_common::backtrace::__rust_end_short_backtrace::hf88150fdc85fc279
  10:        0x10ebf16f6 - _rust_begin_unwind
  11:        0x10ec56b65 - core::panicking::panic_fmt::h2f1aeecb125983ad
  12:        0x11d009e3c - <rustc_const_eval[c24c7cffe455128a]::transform::validate::CfgChecker>::fail::<alloc[358a2b952a6a0aef]::string::String>
  13:        0x11d008efc - <rustc_const_eval[c24c7cffe455128a]::transform::validate::Validator as rustc_middle[a60fef8b9e2255ee]::mir::MirPass>::run_pass
  14:        0x11e067055 - rustc_mir_transform[566a052616cff93f]::pass_manager::run_passes_inner
  15:        0x11e18b7db - rustc_mir_transform[566a052616cff93f]::optimized_mir
  16:        0x11e68d651 - rustc_query_impl[dc288a5418598345]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[dc288a5418598345]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[a60fef8b9e2255ee]::query::erase::Erased<[u8; 8usize]>>
  17:        0x11e6b53ff - <rustc_query_impl[dc288a5418598345]::query_impl::optimized_mir::dynamic_query::{closure#2} as core[3b7fc5b096dd50df]::ops::function::FnOnce<(rustc_middle[a60fef8b9e2255ee]::ty::context::TyCtxt, rustc_span[b271326af215988e]::def_id::DefId)>>::call_once
  18:        0x11e588591 - rustc_query_system[31888a53bbf2e1a0]::query::plumbing::try_execute_query::<rustc_query_impl[dc288a5418598345]::DynamicConfig<rustc_query_system[31888a53bbf2e1a0]::query::caches::DefIdCache<rustc_middle[a60fef8b9e2255ee]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[dc288a5418598345]::plumbing::QueryCtxt, true>
  19:        0x11e859bd4 - rustc_query_impl[dc288a5418598345]::query_impl::optimized_mir::get_query_incr::__rust_end_short_backtrace
  20:        0x11db1aa81 - rustc_middle[a60fef8b9e2255ee]::query::plumbing::query_get_at::<rustc_query_system[31888a53bbf2e1a0]::query::caches::DefIdCache<rustc_middle[a60fef8b9e2255ee]::query::erase::Erased<[u8; 8usize]>>>
  21:        0x11db1f722 - <rustc_metadata[a1b921b2ac881507]::rmeta::encoder::EncodeContext>::encode_crate_root
  22:        0x11db2c7de - rustc_metadata[a1b921b2ac881507]::rmeta::encoder::encode_metadata
  23:        0x11dbb0220 - rustc_metadata[a1b921b2ac881507]::fs::encode_and_write_metadata
  24:        0x11d9b71fb - rustc_interface[7e3dd31bf169c8b9]::passes::start_codegen
  25:        0x11d9c589f - <rustc_middle[a60fef8b9e2255ee]::ty::context::GlobalCtxt>::enter::<<rustc_interface[7e3dd31bf169c8b9]::queries::Queries>::codegen_and_build_linker::{closure#0}, core[3b7fc5b096dd50df]::result::Result<rustc_interface[7e3dd31bf169c8b9]::queries::Linker, rustc_span[b271326af215988e]::ErrorGuaranteed>>
  26:        0x11d987634 - <rustc_interface[7e3dd31bf169c8b9]::queries::Queries>::codegen_and_build_linker
  27:        0x11d0a229b - <rustc_interface[7e3dd31bf169c8b9]::interface::Compiler>::enter::<rustc_driver_impl[963ac894dc08b358]::run_compiler::{closure#0}::{closure#1}, core[3b7fc5b096dd50df]::result::Result<core[3b7fc5b096dd50df]::option::Option<rustc_interface[7e3dd31bf169c8b9]::queries::Linker>, rustc_span[b271326af215988e]::ErrorGuaranteed>>
  28:        0x11d0912b2 - rustc_span[b271326af215988e]::set_source_map::<core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>, rustc_interface[7e3dd31bf169c8b9]::interface::run_compiler<core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>, rustc_driver_impl[963ac894dc08b358]::run_compiler::{closure#0}>::{closure#0}::{closure#0}>
  29:        0x11d092b59 - rustc_span[b271326af215988e]::create_session_globals_then::<core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>, rustc_interface[7e3dd31bf169c8b9]::util::run_in_thread_pool_with_globals<rustc_interface[7e3dd31bf169c8b9]::interface::run_compiler<core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>, rustc_driver_impl[963ac894dc08b358]::run_compiler::{closure#0}>::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>::{closure#0}>
  30:        0x11d0e2565 - std[38e54a1d943a7f58]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[7e3dd31bf169c8b9]::util::run_in_thread_with_globals<rustc_interface[7e3dd31bf169c8b9]::util::run_in_thread_pool_with_globals<rustc_interface[7e3dd31bf169c8b9]::interface::run_compiler<core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>, rustc_driver_impl[963ac894dc08b358]::run_compiler::{closure#0}>::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>
  31:        0x11d0e3633 - <<std[38e54a1d943a7f58]::thread::Builder>::spawn_unchecked_<rustc_interface[7e3dd31bf169c8b9]::util::run_in_thread_with_globals<rustc_interface[7e3dd31bf169c8b9]::util::run_in_thread_pool_with_globals<rustc_interface[7e3dd31bf169c8b9]::interface::run_compiler<core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>, rustc_driver_impl[963ac894dc08b358]::run_compiler::{closure#0}>::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3b7fc5b096dd50df]::result::Result<(), rustc_span[b271326af215988e]::ErrorGuaranteed>>::{closure#1} as core[3b7fc5b096dd50df]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:        0x10ebfb6b9 - std::sys::pal::unix::thread::Thread::new::thread_start::hbdab245be6fda933
  33:     0x7ff80dc144e1 - __pthread_start

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

ChrisDenton commented Feb 29, 2024

Congrats on the ICE! However, using internal features outside of the compiler or standard library is not something we support, even though it may ask you to report it (this is itself a bug). See Policy for ICEs on incorrect usage of internal-only features.

In general any use of internal features may cause ICEs if not used for their intended purpose.

@ChrisDenton ChrisDenton closed this as not planned Won't fix, can't repro, duplicate, stale Feb 29, 2024
@scottmcm
Copy link
Member

To further demonstrate that this is just what happens for a misuse of intrinsics, note that the repro can be simplified to

#![feature(core_intrinsics)]
pub fn add<T: Copy>(a: T, b: T) {
    let _result = core::intrinsics::add_with_overflow(a, b);
}

They're not really generic. They're an internal hack for the core library only.

@saethlin saethlin removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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