Skip to content

ICE while using TaggedPtr' compile-time evaluations. #124400

Closed
@Alonely0

Description

@Alonely0

I encountered an ICE while playing with tagged_pointer's TaggedPtr that has to do with its comptime assertions. I have not been able to reproduce the ICE when inlining the constant value in which the checks are performed. Perhaps it is related with the fact that originally there was a crate boundary? I have an inkling const blocks' merger might be to blame.

ICE file

Code

use tagged_pointer::TaggedPtr; // version = 0.2.7
struct Foo;
TaggedPtr::<_, 2>::new(NonNull::from(&Foo), 0x1);

Meta

rustc --version --verbose:

rustc 1.79.0-nightly (3a36386dc 2024-04-25)
binary: rustc
commit-hash: 3a36386dc1075018dc7ca2640a2656adb31a61fe
commit-date: 2024-04-25
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Error output

error[E0080]: evaluation of `tagged_pointer::<impl tagged_pointer::ptr::PtrImpl<engine::layout::tests::test_iter::Foo, 2>>::ASSERT` failed
   --> /home/guillem/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tagged-pointer-0.2.7/src/lib.rs:161:9
    |
161 |         ["alignment of `T` must be at least `1 << BITS`"][!b as usize];
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ index out of bounds: the length is 1 but the index is 1

error: internal compiler error: compiler/rustc_middle/src/mir/mod.rs:705:17: Couldn't evaluate constant const tagged_pointer::<impl tagged_pointer::ptr::PtrImpl<T, BITS>>::ASSERT in mono Instance { def: Item(DefId(25:58 ~ tagged_pointer[1ee3]::{impl#0}::assert)), args: [engine::layout::tests::test_iter::Foo, 2_usize] }

thread 'rustc' panicked at compiler/rustc_middle/src/mir/mod.rs:705:17:
Box<dyn Any>
Backtrace

stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: <rustc_errors::diagnostic::BugAbort as rustc_errors::diagnostic::EmissionGuarantee>::emit_producing_guarantee
   2: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>::{closure#0}
   3: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}
   4: rustc_middle::ty::context::tls::with_context_opt::<rustc_middle::ty::context::tls::with_opt<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
   5: rustc_middle::util::bug::bug_fmt
   6: rustc_monomorphize::collector::collect_items_rec::{closure#0}
   7: rustc_monomorphize::collector::collect_items_rec
   8: rustc_monomorphize::collector::collect_items_rec
   9: rustc_monomorphize::collector::collect_items_rec
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::collector::collect_items_rec
  12: rustc_monomorphize::collector::collect_items_rec
  13: rustc_monomorphize::partitioning::collect_and_partition_mono_items
      [... omitted 2 frames ...]
  14: rustc_codegen_ssa::base::codegen_crate::<rustc_codegen_llvm::LlvmCodegenBackend>
  15: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  16: rustc_interface::passes::start_codegen
  17: <rustc_interface::queries::Queries>::codegen_and_build_linker
  18: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}

Metadata

Metadata

Assignees

Labels

A-monomorphizationArea: MonomorphizationC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️S-has-mcveStatus: A Minimal Complete and Verifiable Example has been found for this issueT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions