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 while using TaggedPtr' compile-time evaluations. #124400

Closed
Alonely0 opened this issue Apr 26, 2024 · 5 comments · Fixed by #124425
Closed

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

Alonely0 opened this issue Apr 26, 2024 · 5 comments · Fixed by #124425
Assignees
Labels
A-monomorphization Area: Monomorphization C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

@Alonely0
Copy link

Alonely0 commented Apr 26, 2024

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}

@Alonely0 Alonely0 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 26, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 26, 2024
@Noratrieb Noratrieb added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Apr 26, 2024
@Noratrieb
Copy link
Member

It would be useful to have a minimal example that doesn't involve the entire tagged_ptr crate.

@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 26, 2024
@lukas-code
Copy link
Member

Reduced: playground, needs cargo build

struct Bar<const BITS: usize>;

impl<const BITS: usize> Bar<BITS> {
    const ASSERT: bool = {
        let b = std::convert::identity(1);
        ["oops"][b];
        true
    };

    fn assert() {
        let val = Self::ASSERT;
        if val {
            std::convert::identity(val);
        }
    }
}


fn main() {
    Bar::<0>::assert();
}

This bisects to #123272 cc @saethlin

@rustbot label A-monomorphization S-has-mcve -E-needs-mcve

@rustbot rustbot added A-monomorphization Area: Monomorphization S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Apr 26, 2024
@saethlin saethlin self-assigned this Apr 26, 2024
@saethlin
Copy link
Member

ye olde "compiler must not crash on invalid code" problem

@saethlin
Copy link
Member

saethlin commented Apr 27, 2024

PR with a fix is up. Thanks for catching this before the bug hit beta @Alonely0!

@Alonely0
Copy link
Author

PR with a fix is up. Thanks for catching this before the bug hit beta @Alonely0!

No, thanks to you all for not only fixing it, but running this amazing project every day. I hope I have more time in the future so that I can spend it here and be a part of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-monomorphization Area: Monomorphization C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ 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

Successfully merging a pull request may close this issue.

5 participants