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

Assertion fails at compiler/rustc_const_eval/src/interpret/validity.rs:763:21 #133581

Closed
ethanbarry opened this issue Nov 28, 2024 · 3 comments
Closed
Labels
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

@ethanbarry
Copy link

I was helping a friend with some basic multi-threading, and tried compiling a modified example of his. rustc gave me the expected errors before I commented out let flag = ... and added static flag = .... After that, it crashed with the error message below.

To reproduce it, make sure the target/ directory does not exist. When I swapped to a working example, which compiled as expected, I could not reproduce the error until doing rm -rf target.

Code

use std::sync::atomic::Ordering;
use std::sync::atomic::AtomicBool;

use std::thread;

static flag = AtomicBool::new(false);

fn main() {
    //    let flag = AtomicBool::new(false);
    
    thread::spawn(|| {
        do_something(flag);
    });
    thread::spawn(|| {
        do_something_else(&flag);
    });
}

fn do_something(mut f: AtomicBool) {
    let mut counter = 0;
    println!("Starting counting...");
    while counter != 10 {
        counter += 1;
    }
    println!("The counter has reached 10!");
    println!("Setting the Atomic Bool to true...");
    *f.get_mut() = true;
    println!("The Atomic Bool has been set!");
}

fn do_something_else(f: &AtomicBool) {
    let mut counter  = 0_u64;
    println!("Entering the loop...");
    loop {
        if f.load(Ordering::SeqCst) {
            println!("Looped {} before exiting!", counter);
            break;
        } else {
            counter += 1;
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1

Error output

    Checking testatomics v0.1.0 (/run/media/ethan/TERABYTE/Development/Rust/testatomics)
error: missing type for `static` item
 --> src/main.rs:6:12
  |
6 | static flag = AtomicBool::new(false);
  |            ^ help: provide a type for the static variable: `: AtomicBool`

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:763:21:
assertion `left == right` failed
  left: Mut
 right: Not
stack backtrace:
   0:     0x705d8c9ce6ea - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h304520fd6a30aa07
   1:     0x705d8d219525 - core::fmt::write::hf5713710ce10ff22
   2:     0x705d8e034d91 - std::io::Write::write_fmt::hda708db57927dacf
   3:     0x705d8c9d0dbb - std::panicking::default_hook::{{closure}}::he1ad87607d0c11c5
   4:     0x705d8c9d0a2e - std::panicking::default_hook::h81c8cd2e7c59ee33
   5:     0x705d8bb9a5d7 - std[5204e9590b4985ef]::panicking::update_hook::<alloc[fd15fd9026f491e1]::boxed::Box<rustc_driver_impl[c41f2638408ed175]::install_ice_hook::{closure#0}>>::{closure#0}
   6:     0x705d8c9d16d7 - std::panicking::rust_panic_with_hook::had2118629c312a4a
   7:     0x705d8c9d1397 - std::panicking::begin_panic_handler::{{closure}}::h7fa5985d111bafa2
   8:     0x705d8c9ceb99 - std::sys::backtrace::__rust_end_short_backtrace::h704d151dbefa09c5
   9:     0x705d8c9d1064 - rust_begin_unwind
  10:     0x705d8a058413 - core::panicking::panic_fmt::h3eea515d05f7a35e
  11:     0x705d8b5b837e - core::panicking::assert_failed_inner::h11b1378688fb0090
  12:     0x705d8bafc3f3 - core[d89802b8f5f07590]::panicking::assert_failed::<rustc_ast_ir[5aeba6af154013f1]::Mutability, rustc_ast_ir[5aeba6af154013f1]::Mutability>
  13:     0x705d8eb74449 - <rustc_const_eval[a19edbaf594cd2d5]::interpret::validity::ValidityVisitor<rustc_const_eval[a19edbaf594cd2d5]::const_eval::machine::CompileTimeMachine>>::in_mutable_memory.cold
  14:     0x705d8d2540a9 - <rustc_const_eval[a19edbaf594cd2d5]::interpret::validity::ValidityVisitor<rustc_const_eval[a19edbaf594cd2d5]::const_eval::machine::CompileTimeMachine> as rustc_const_eval[a19edbaf594cd2d5]::interpret::visitor::ValueVisitor<rustc_const_eval[a19edbaf594cd2d5]::const_eval::machine::CompileTimeMachine>>::visit_value
  15:     0x705d8d2530cb - <rustc_const_eval[a19edbaf594cd2d5]::interpret::validity::ValidityVisitor<rustc_const_eval[a19edbaf594cd2d5]::const_eval::machine::CompileTimeMachine> as rustc_const_eval[a19edbaf594cd2d5]::interpret::visitor::ValueVisitor<rustc_const_eval[a19edbaf594cd2d5]::const_eval::machine::CompileTimeMachine>>::visit_value
  16:     0x705d8e09324a - <rustc_const_eval[a19edbaf594cd2d5]::interpret::eval_context::InterpCx<rustc_const_eval[a19edbaf594cd2d5]::const_eval::machine::CompileTimeMachine>>::validate_operand_internal
  17:     0x705d8d277119 - rustc_const_eval[a19edbaf594cd2d5]::const_eval::eval_queries::eval_body_using_ecx::<rustc_middle[c83967c7761a8780]::mir::interpret::allocation::ConstAllocation>
  18:     0x705d8e0abaf1 - rustc_const_eval[a19edbaf594cd2d5]::const_eval::eval_queries::eval_static_initializer_provider
  19:     0x705d8e0ab82b - rustc_query_impl[2ecbb548ea5419f8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2ecbb548ea5419f8]::query_impl::eval_static_initializer::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c83967c7761a8780]::query::erase::Erased<[u8; 16usize]>>
  20:     0x705d8e0ab80d - <rustc_query_impl[2ecbb548ea5419f8]::query_impl::eval_static_initializer::dynamic_query::{closure#2} as core[d89802b8f5f07590]::ops::function::FnOnce<(rustc_middle[c83967c7761a8780]::ty::context::TyCtxt, rustc_span[233999951ced9cd1]::def_id::DefId)>>::call_once
  21:     0x705d8d766663 - rustc_query_system[842c6bba149f2c70]::query::plumbing::try_execute_query::<rustc_query_impl[2ecbb548ea5419f8]::DynamicConfig<rustc_query_system[842c6bba149f2c70]::query::caches::DefIdCache<rustc_middle[c83967c7761a8780]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[2ecbb548ea5419f8]::plumbing::QueryCtxt, true>
  22:     0x705d8e1d40f4 - rustc_query_impl[2ecbb548ea5419f8]::query_impl::eval_static_initializer::get_query_incr::__rust_end_short_backtrace
  23:     0x705d8d72e274 - rustc_hir_analysis[f6b76c600746b263]::check_crate
  24:     0x705d8dc498b4 - rustc_interface[706ab71263ce060a]::passes::run_required_analyses
  25:     0x705d8dc41da5 - rustc_interface[706ab71263ce060a]::passes::analysis
  26:     0x705d8dc41d89 - rustc_query_impl[2ecbb548ea5419f8]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[2ecbb548ea5419f8]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c83967c7761a8780]::query::erase::Erased<[u8; 1usize]>>
  27:     0x705d8e3565d9 - rustc_query_system[842c6bba149f2c70]::query::plumbing::try_execute_query::<rustc_query_impl[2ecbb548ea5419f8]::DynamicConfig<rustc_query_system[842c6bba149f2c70]::query::caches::SingleCache<rustc_middle[c83967c7761a8780]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[2ecbb548ea5419f8]::plumbing::QueryCtxt, true>
  28:     0x705d8e3562b8 - rustc_query_impl[2ecbb548ea5419f8]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace
  29:     0x705d8df860b2 - rustc_interface[706ab71263ce060a]::interface::run_compiler::<core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>, rustc_driver_impl[c41f2638408ed175]::run_compiler::{closure#0}>::{closure#1}
  30:     0x705d8e03ed16 - std[5204e9590b4985ef]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[706ab71263ce060a]::util::run_in_thread_with_globals<rustc_interface[706ab71263ce060a]::interface::run_compiler<core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>, rustc_driver_impl[c41f2638408ed175]::run_compiler::{closure#0}>::{closure#1}, core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>>
  31:     0x705d8e0779b0 - <<std[5204e9590b4985ef]::thread::Builder>::spawn_unchecked_<rustc_interface[706ab71263ce060a]::util::run_in_thread_with_globals<rustc_interface[706ab71263ce060a]::interface::run_compiler<core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>, rustc_driver_impl[c41f2638408ed175]::run_compiler::{closure#0}>::{closure#1}, core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[d89802b8f5f07590]::result::Result<(), rustc_span[233999951ced9cd1]::ErrorGuaranteed>>::{closure#1} as core[d89802b8f5f07590]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x705d8e077d2b - std::sys::pal::unix::thread::Thread::new::thread_start::hcdbd1049068002f4
  33:     0x705d886a339d - <unknown>
  34:     0x705d8872849c - <unknown>
  35:                0x0 - <unknown>

error: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.82.0 (f6e511eec 2024-10-15) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `flag`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `testatomics` (bin "testatomics") due to 1 previous error
Backtrace

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/validity.rs:763:21:
assertion `left == right` failed
  left: Mut
 right: Not
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed::<rustc_ast_ir::Mutability, rustc_ast_ir::Mutability>
   4: <rustc_const_eval::interpret::validity::ValidityVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::in_mutable_memory.cold
   5: <rustc_const_eval::interpret::validity::ValidityVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine> as rustc_const_eval::interpret::visitor::ValueVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::visit_value
   6: <rustc_const_eval::interpret::validity::ValidityVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine> as rustc_const_eval::interpret::visitor::ValueVisitor<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::visit_value
   7: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::machine::CompileTimeMachine>>::validate_operand_internal
   8: rustc_const_eval::const_eval::eval_queries::eval_body_using_ecx::<rustc_middle::mir::interpret::allocation::ConstAllocation>
   9: rustc_const_eval::const_eval::eval_queries::eval_static_initializer_provider
      [... omitted 2 frames ...]
  10: rustc_hir_analysis::check_crate
  11: rustc_interface::passes::run_required_analyses
  12: rustc_interface::passes::analysis
      [... omitted 1 frame ...]
  13: rustc_interface::interface::run_compiler::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

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: rustc 1.82.0 (f6e511eec 2024-10-15) running on x86_64-unknown-linux-gnu

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental=[REDACTED]

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [eval_static_initializer] evaluating initializer of static `flag`
#1 [analysis] running analysis passes on this crate
end of query stack
error: could not compile `testatomics` (bin "testatomics") due to 1 previous error

@ethanbarry ethanbarry 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 Nov 28, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 28, 2024
@cyrgani
Copy link
Contributor

cyrgani commented Nov 28, 2024

This is a duplicate of #124164 and already fixed in todays 1.83.0 release.

@ethanbarry
Copy link
Author

This is a duplicate of #124164 and already fixed in todays 1.83.0 release.

Ah! Didn't notice we had a new version!

@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 29, 2024
@jieyouxu
Copy link
Member

Closing as duplicate of #124164.

@jieyouxu jieyouxu closed this as not planned Won't fix, can't repro, duplicate, stale Nov 29, 2024
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) ❄️ 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

4 participants