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: "assertion failed: *old == value" in optimized + incremental builds #126741

Closed
BobG1983 opened this issue Jun 20, 2024 · 16 comments
Closed

ICE: "assertion failed: *old == value" in optimized + incremental builds #126741

BobG1983 opened this issue Jun 20, 2024 · 16 comments
Assignees
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-incr-comp Area: Incremental compilation 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

@BobG1983
Copy link

Repro:

Rustc Version: rustc 1.81.0-nightly (59e2c01 2024-06-17)
Toolchain: nightly-x86_64-pc-windows-msvc

What I did:
Clone https://github.com/BobG1983/rantz_random.git
run cargo test
run cargo test again.

Issue:

The compiler panics with the following output:

thread 'rustc' panicked at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db\compiler\rustc_data_structures\src\sync.rs:338:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffe2a00d5d3 - std::backtrace::Backtrace::create
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:331
   3:     0x7ffe2a00d51a - std::backtrace::Backtrace::force_capture
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:312
   4:     0x7ffde674e510 - memchr
   5:     0x7ffe2a027337 - alloc::boxed::impl$50::call
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2076
   6:     0x7ffe2a027337 - std::panicking::rust_panic_with_hook
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:801
   7:     0x7ffe2a02710f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:660
   8:     0x7ffe2a0245af - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\backtrace.rs:171
   9:     0x7ffe2a026d66 - std::panicking::begin_panic_handler
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:658
  10:     0x7ffe2a07cf64 - core::panicking::panic_fmt
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:74
  11:     0x7ffe2a07d00d - core::panicking::panic
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:148
  12:     0x7ffde51a4443 - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::set_alloc_id_same_memory
  13:     0x7ffde507a807 - <rustc_metadata[beec48ef7521b97d]::rmeta::decoder::DecodeContext as rustc_type_ir[69993b1d9e925772]::codec::TyDecoder>::decode_alloc_id
  14:     0x7ffde6247d9b - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  15:     0x7ffde6232446 - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  16:     0x7ffde62cdfc3 - <rustc_metadata[beec48ef7521b97d]::creader::alloc_error_handler_spans::Finder as rustc_ast[9ac2f267a929ff38]::visit::Visitor>::visit_item
  17:     0x7ffde5d3de6b - rustc_query_impl[f350898e45c5ba56]::plumbing::query_key_hash_verify_all
  18:     0x7ffde5c3453e - rustc_ty_utils[4ce48a55c0187f78]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  19:     0x7ffde4e95ad5 - rustc_query_impl[f350898e45c5ba56]::query_system
  20:     0x7ffde661731f - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::instance_mir
  21:     0x7ffde61d8ab3 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  22:     0x7ffde61d5bc9 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  23:     0x7ffde61d7872 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  24:     0x7ffde76ebb5d - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  25:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  26:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  27:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  28:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  29:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  30:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  31:     0x7ffde76f5a57 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  32:     0x7ffde7db1669 - <rayon_core[744fdfe6ee7fdbd]::registry::WorkerThread>::wait_until_cold
  33:     0x7ffde7dadc35 - <rayon_core[744fdfe6ee7fdbd]::registry::ThreadBuilder>::run
  34:     0x7ffde67514dc - memchr
  35:     0x7ffde6745efd - memchr
  36:     0x7ffde6750dd1 - memchr
  37:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  38:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  39:     0x7ffe2a03834d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\pal\windows\thread.rs:52
  40:     0x7ffeb94c257d - BaseThreadInitThunk
  41:     0x7ffeba70af28 - RtlUserThreadStart


rustc version: 1.81.0-nightly (59e2c01c2 2024-06-17)
platform: x86_64-pc-windows-msvc

query stack during panic:
#0 [optimized_mir] optimizing MIR for `fastrand::global_rng::u128`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
thread 'rustc' panicked at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db\compiler\rustc_data_structures\src\sync.rs:338:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffe2a00d5d3 - std::backtrace::Backtrace::create
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:331
   3:     0x7ffe2a00d51a - std::backtrace::Backtrace::force_capture
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:312
   4:     0x7ffde674e510 - memchr
   5:     0x7ffe2a027337 - alloc::boxed::impl$50::call
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2076
   6:     0x7ffe2a027337 - std::panicking::rust_panic_with_hook
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:801
   7:     0x7ffe2a02710f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:660
   8:     0x7ffe2a0245af - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\backtrace.rs:171
   9:     0x7ffe2a026d66 - std::panicking::begin_panic_handler
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:658
  10:     0x7ffe2a07cf64 - core::panicking::panic_fmt
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:74
  11:     0x7ffe2a07d00d - core::panicking::panic
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:148
  12:     0x7ffde51a4443 - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::set_alloc_id_same_memory
  13:     0x7ffde507a807 - <rustc_metadata[beec48ef7521b97d]::rmeta::decoder::DecodeContext as rustc_type_ir[69993b1d9e925772]::codec::TyDecoder>::decode_alloc_id
  14:     0x7ffde6247d9b - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  15:     0x7ffde6232446 - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  16:     0x7ffde62cdfc3 - <rustc_metadata[beec48ef7521b97d]::creader::alloc_error_handler_spans::Finder as rustc_ast[9ac2f267a929ff38]::visit::Visitor>::visit_item
  17:     0x7ffde5d3de6b - rustc_query_impl[f350898e45c5ba56]::plumbing::query_key_hash_verify_all
  18:     0x7ffde5c3453e - rustc_ty_utils[4ce48a55c0187f78]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  19:     0x7ffde4e95ad5 - rustc_query_impl[f350898e45c5ba56]::query_system
  20:     0x7ffde661731f - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::instance_mir
  21:     0x7ffde61d8ab3 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  22:     0x7ffde61d5bc9 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  23:     0x7ffde61d7872 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  24:     0x7ffde76ebb5d - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  25:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  26:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  27:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  28:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  29:     0x7ffde76f5a57 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  30:     0x7ffde7db1669 - <rayon_core[744fdfe6ee7fdbd]::registry::WorkerThread>::wait_until_cold
  31:     0x7ffde7dadc35 - <rayon_core[744fdfe6ee7fdbd]::registry::ThreadBuilder>::run
  32:     0x7ffde67514dc - memchr
  33:     0x7ffde6745efd - memchr
  34:     0x7ffde6750dd1 - memchr
  35:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  36:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  37:     0x7ffe2a03834d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\pal\windows\thread.rs:52
  38:     0x7ffeb94c257d - BaseThreadInitThunk
  39:     0x7ffeba70af28 - RtlUserThreadStart


query stack during panic:
#0 [optimized_mir] optimizing MIR for `fastrand::global_rng::i64`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
thread 'rustc' panicked at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db\compiler\rustc_data_structures\src\sync.rs:338:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffe2a00d5d3 - std::backtrace::Backtrace::create
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:331
   3:     0x7ffe2a00d51a - std::backtrace::Backtrace::force_capture
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:312
   4:     0x7ffde674e510 - memchr
   5:     0x7ffe2a027337 - alloc::boxed::impl$50::call
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2076
   6:     0x7ffe2a027337 - std::panicking::rust_panic_with_hook
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:801
   7:     0x7ffe2a02710f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:660
   8:     0x7ffe2a0245af - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\backtrace.rs:171
   9:     0x7ffe2a026d66 - std::panicking::begin_panic_handler
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:658
  10:     0x7ffe2a07cf64 - core::panicking::panic_fmt
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:74
  11:     0x7ffe2a07d00d - core::panicking::panic
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:148
  12:     0x7ffde51a4443 - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::set_alloc_id_same_memory
  13:     0x7ffde507a807 - <rustc_metadata[beec48ef7521b97d]::rmeta::decoder::DecodeContext as rustc_type_ir[69993b1d9e925772]::codec::TyDecoder>::decode_alloc_id
  14:     0x7ffde6247d9b - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  15:     0x7ffde6232446 - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  16:     0x7ffde62cdfc3 - <rustc_metadata[beec48ef7521b97d]::creader::alloc_error_handler_spans::Finder as rustc_ast[9ac2f267a929ff38]::visit::Visitor>::visit_item
  17:     0x7ffde5d3de6b - rustc_query_impl[f350898e45c5ba56]::plumbing::query_key_hash_verify_all
  18:     0x7ffde5c3453e - rustc_ty_utils[4ce48a55c0187f78]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  19:     0x7ffde4e95ad5 - rustc_query_impl[f350898e45c5ba56]::query_system
  20:     0x7ffde661731f - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::instance_mir
  21:     0x7ffde61d8ab3 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  22:     0x7ffde61d5bc9 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  23:     0x7ffde61d7872 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  24:     0x7ffde76ebb5d - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  25:     0x7ffde76f0814 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  26:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  27:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  28:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  29:     0x7ffde76f5a57 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  30:     0x7ffde7db1669 - <rayon_core[744fdfe6ee7fdbd]::registry::WorkerThread>::wait_until_cold
  31:     0x7ffde7dadc35 - <rayon_core[744fdfe6ee7fdbd]::registry::ThreadBuilder>::run
  32:     0x7ffde67514dc - memchr
  33:     0x7ffde6745efd - memchr
  34:     0x7ffde6750dd1 - memchr
  35:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  36:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  37:     0x7ffe2a03834d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\pal\windows\thread.rs:52
  38:     0x7ffeb94c257d - BaseThreadInitThunk
  39:     0x7ffeba70af28 - RtlUserThreadStart


query stack during panic:
#0 [optimized_mir] optimizing MIR for `fastrand::global_rng::i8`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
thread 'rustc' panicked at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db\compiler\rustc_data_structures\src\sync.rs:338:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffe2a00d5d3 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffe2a00d5d3 - std::backtrace::Backtrace::create
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:331
   3:     0x7ffe2a00d51a - std::backtrace::Backtrace::force_capture
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\backtrace.rs:312
   4:     0x7ffde674e510 - memchr
   5:     0x7ffe2a027337 - alloc::boxed::impl$50::call
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2076
   6:     0x7ffe2a027337 - std::panicking::rust_panic_with_hook
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:801
   7:     0x7ffe2a02710f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:660
   8:     0x7ffe2a0245af - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\backtrace.rs:171
   9:     0x7ffe2a026d66 - std::panicking::begin_panic_handler
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\panicking.rs:658
  10:     0x7ffe2a07cf64 - core::panicking::panic_fmt
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:74
  11:     0x7ffe2a07d00d - core::panicking::panic
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\core\src\panicking.rs:148
  12:     0x7ffde51a4443 - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::set_alloc_id_same_memory
  13:     0x7ffde507a807 - <rustc_metadata[beec48ef7521b97d]::rmeta::decoder::DecodeContext as rustc_type_ir[69993b1d9e925772]::codec::TyDecoder>::decode_alloc_id
  14:     0x7ffde6247d9b - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  15:     0x7ffde6232446 - <aho_corasick[ac69cc43042af094]::util::prefilter::Builder>::build
  16:     0x7ffde62cdfc3 - <rustc_metadata[beec48ef7521b97d]::creader::alloc_error_handler_spans::Finder as rustc_ast[9ac2f267a929ff38]::visit::Visitor>::visit_item
  17:     0x7ffde5d3de6b - rustc_query_impl[f350898e45c5ba56]::plumbing::query_key_hash_verify_all
  18:     0x7ffde5c3453e - rustc_ty_utils[4ce48a55c0187f78]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  19:     0x7ffde4e95ad5 - rustc_query_impl[f350898e45c5ba56]::query_system
  20:     0x7ffde661731f - <rustc_middle[3720665636316a56]::ty::context::TyCtxt>::instance_mir
  21:     0x7ffde61d8ab3 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  22:     0x7ffde61d5bc9 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  23:     0x7ffde61d7872 - rustc_monomorphize[cd4d3c758268f64]::is_call_from_compiler_builtins_to_upstream_monomorphization
  24:     0x7ffde76ebb5d - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  25:     0x7ffde76f0727 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  26:     0x7ffde76ebe18 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  27:     0x7ffde76f5a57 - <gimli[87f9d3ffa14e46ff]::write::str::LineStringTable>::get
  28:     0x7ffde7db1669 - <rayon_core[744fdfe6ee7fdbd]::registry::WorkerThread>::wait_until_cold
  29:     0x7ffde7dadc35 - <rayon_core[744fdfe6ee7fdbd]::registry::ThreadBuilder>::run
  30:     0x7ffde67514dc - memchr
  31:     0x7ffde6745efd - memchr
  32:     0x7ffde6750dd1 - memchr
  33:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  34:     0x7ffe2a03834d - alloc::boxed::impl$48::call_once
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\alloc\src\boxed.rs:2062
  35:     0x7ffe2a03834d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library\std\src\sys\pal\windows\thread.rs:52
  36:     0x7ffeb94c257d - BaseThreadInitThunk
  37:     0x7ffeba70af28 - RtlUserThreadStart


query stack during panic:
#0 [optimized_mir] optimizing MIR for `fastrand::global_rng::i16`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
@BobG1983 BobG1983 added the C-bug Category: This is a bug. label Jun 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 20, 2024
@Nemo157
Copy link
Member

Nemo157 commented Jun 27, 2024

I just got a very similar ICE while compiling a proprietary codebase

thread 'rustc' panicked at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/compiler/rustc_data_structures/src/sync.rs:338:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7f6fe6d44975 - std::backtrace_rs::backtrace::libunwind::trace::h184e33fa7a4efbe9
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f6fe6d44975 - std::backtrace_rs::backtrace::trace_unsynchronized::hc3eac562c05961d9
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f6fe6d44975 - std::backtrace::Backtrace::create::h85924e152703a8fb
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/backtrace.rs:331:13
   3:     0x7f6fe6d448c5 - std::backtrace::Backtrace::force_capture::h3dc650b8da4f2095
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/backtrace.rs:312:9
   4:     0x7f6fea0c7206 - std[c3fbaf9a0386b13c]::panicking::update_hook::<alloc[3df32a5d58f536a7]::boxed::Box<rustc_driver_impl[ee4d79150a07c4f8]::install_ice_hook::{closure#0}>>::{closure#0}
   5:     0x7f6fe6d5fa4f - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::ha3b0d962ec1ff02b
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/alloc/src/boxed.rs:2076:9
   6:     0x7f6fe6d5fa4f - std::panicking::rust_panic_with_hook::h0adf1873cdd8ce86
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/panicking.rs:801:13
   7:     0x7f6fe6d5f643 - std::panicking::begin_panic_handler::{{closure}}::h14e7b85ca1885ac4
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/panicking.rs:660:13
   8:     0x7f6fe6d5cdf9 - std::sys::backtrace::__rust_end_short_backtrace::h17e9af05fae71c34
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/sys/backtrace.rs:171:18
   9:     0x7f6fe6d5f324 - rust_begin_unwind
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/panicking.rs:658:5
  10:     0x7f6fe6da9a73 - core::panicking::panic_fmt::h273dffa90a45a379
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/core/src/panicking.rs:74:14
  11:     0x7f6fe6da9afc - core::panicking::panic::hf430b0f328d1e0c3
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/core/src/panicking.rs:148:5
  12:     0x7f6febda652a - <rustc_middle[516cb2fde7e58e9c]::ty::context::TyCtxt>::set_alloc_id_same_memory
  13:     0x7f6febda817a - <rustc_metadata[7225a1edc81ce069]::rmeta::decoder::DecodeContext as rustc_type_ir[c8111a7f01cd6547]::codec::TyDecoder>::decode_alloc_id
  14:     0x7f6fec689761 - <rustc_middle[516cb2fde7e58e9c]::mir::syntax::Operand as rustc_serialize[cdae1fdc1aabbafe]::serialize::Decodable<rustc_metadata[7225a1edc81ce069]::rmeta::decoder::DecodeContext>>::decode.warm
  15:     0x7f6feb6de740 - <rustc_middle[516cb2fde7e58e9c]::mir::Body as rustc_serialize[cdae1fdc1aabbafe]::serialize::Decodable<rustc_metadata[7225a1edc81ce069]::rmeta::decoder::DecodeContext>>::decode
  16:     0x7f6febb995cc - rustc_metadata[7225a1edc81ce069]::rmeta::decoder::cstore_impl::provide_extern::optimized_mir
  17:     0x7f6febb992f5 - rustc_query_impl[250cb7a150488de5]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[250cb7a150488de5]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[516cb2fde7e58e9c]::query::erase::Erased<[u8; 8usize]>>
  18:     0x7f6feb7bb290 - rustc_query_system[7ef52ba0f7b4d7c0]::query::plumbing::try_execute_query::<rustc_query_impl[250cb7a150488de5]::DynamicConfig<rustc_query_system[7ef52ba0f7b4d7c0]::query::caches::DefIdCache<rustc_middle[516cb2fde7e58e9c]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[250cb7a150488de5]::plumbing::QueryCtxt, true>
  19:     0x7f6feb7b872b - rustc_query_impl[250cb7a150488de5]::query_impl::optimized_mir::get_query_incr::__rust_end_short_backtrace
  20:     0x7f6febbac55d - <rustc_middle[516cb2fde7e58e9c]::ty::context::TyCtxt>::instance_mir
  21:     0x7f6fec26dc28 - rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_items_rec::{closure#0}
  22:     0x7f6feb48a707 - rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_items_rec
  23:     0x7f6feb48ae91 - rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_items_rec
  24:     0x7f6feb48ae91 - rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_items_rec
  25:     0x7f6feb48ae91 - rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_items_rec
  26:     0x7f6fea7b5704 - rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper::<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>
  27:     0x7f6fea7bcf2d - <rayon_core[36277e153e91b8ec]::job::StackJob<rayon_core[36277e153e91b8ec]::latch::SpinLatch, rayon_core[36277e153e91b8ec]::join::join_context::call_b<(), rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}>::{closure#0}, ()> as rayon_core[36277e153e91b8ec]::job::Job>::execute
  28:     0x7f6fe9c8e3c9 - <rayon_core[36277e153e91b8ec]::registry::WorkerThread>::wait_until_cold
  29:     0x7f6fea7b9388 - rayon_core[36277e153e91b8ec]::join::join_context::<rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>::{closure#0}, rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}, (), ()>::{closure#0}
  30:     0x7f6fea7b58d1 - rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper::<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>
  31:     0x7f6fea7b9417 - rayon_core[36277e153e91b8ec]::join::join_context::<rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>::{closure#0}, rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}, (), ()>::{closure#0}
  32:     0x7f6fea7b58d1 - rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper::<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>
  33:     0x7f6fea7bcf2d - <rayon_core[36277e153e91b8ec]::job::StackJob<rayon_core[36277e153e91b8ec]::latch::SpinLatch, rayon_core[36277e153e91b8ec]::join::join_context::call_b<(), rayon[92163da674b3e24f]::iter::plumbing::bridge_producer_consumer::helper<rayon[92163da674b3e24f]::vec::DrainProducer<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rayon[92163da674b3e24f]::iter::for_each::ForEachConsumer<rustc_data_structures[25e7fbd825e2c556]::sync::parallel::enabled::par_for_each_in<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem, alloc[3df32a5d58f536a7]::vec::Vec<rustc_middle[516cb2fde7e58e9c]::mir::mono::MonoItem>, rustc_monomorphize[d5fadf6a90eab74c]::collector::collect_crate_mono_items::{closure#1}::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}>::{closure#0}, ()> as rayon_core[36277e153e91b8ec]::job::Job>::execute
  34:     0x7f6fe9c8e3c9 - <rayon_core[36277e153e91b8ec]::registry::WorkerThread>::wait_until_cold
  35:     0x7f6fe9c8b2e9 - <rayon_core[36277e153e91b8ec]::registry::ThreadBuilder>::run
  36:     0x7f6fea0c9057 - <<crossbeam_utils[1c122dd7a40468ca]::thread::ScopedThreadBuilder>::spawn<<rayon_core[36277e153e91b8ec]::ThreadPoolBuilder>::build_scoped<rustc_interface[ad92266d8770ef5]::util::run_in_thread_pool_with_globals<rustc_interface[ad92266d8770ef5]::interface::run_compiler<core[2498b3506ce20dac]::result::Result<(), rustc_span[72d27a3883823780]::ErrorGuaranteed>, rustc_driver_impl[ee4d79150a07c4f8]::run_compiler::{closure#0}>::{closure#1}, core[2498b3506ce20dac]::result::Result<(), rustc_span[72d27a3883823780]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface[ad92266d8770ef5]::util::run_in_thread_pool_with_globals<rustc_interface[ad92266d8770ef5]::interface::run_compiler<core[2498b3506ce20dac]::result::Result<(), rustc_span[72d27a3883823780]::ErrorGuaranteed>, rustc_driver_impl[ee4d79150a07c4f8]::run_compiler::{closure#0}>::{closure#1}, core[2498b3506ce20dac]::result::Result<(), rustc_span[72d27a3883823780]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core[2498b3506ce20dac]::result::Result<(), rustc_span[72d27a3883823780]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core[2498b3506ce20dac]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  37:     0x7f6fea0c171e - std[c3fbaf9a0386b13c]::sys::backtrace::__rust_begin_short_backtrace::<alloc[3df32a5d58f536a7]::boxed::Box<dyn core[2498b3506ce20dac]::ops::function::FnOnce<(), Output = ()> + core[2498b3506ce20dac]::marker::Send>, ()>
  38:     0x7f6fea0c8d05 - <<std[c3fbaf9a0386b13c]::thread::Builder>::spawn_unchecked_<alloc[3df32a5d58f536a7]::boxed::Box<dyn core[2498b3506ce20dac]::ops::function::FnOnce<(), Output = ()> + core[2498b3506ce20dac]::marker::Send>, ()>::{closure#2} as core[2498b3506ce20dac]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  39:     0x7f6fe6d698cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h415b3c48feec9148
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/alloc/src/boxed.rs:2062:9
  40:     0x7f6fe6d698cb - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h0d4446e047e96116
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/alloc/src/boxed.rs:2062:9
  41:     0x7f6fe6d698cb - std::sys::pal::unix::thread::Thread::new::thread_start::h01071f1a69504322
                               at /rustc/59e2c01c2217a01546222e4d9ff4e6695ee8a1db/library/std/src/sys/pal/unix/thread.rs:108:17
  42:     0x7f6fe6b47272 - start_thread
  43:     0x7f6fe6bc2dec - __GI___clone3
  44:                0x0 - <unknown>


rustc version: 1.81.0-nightly (59e2c01c2 2024-06-17)
platform: x86_64-unknown-linux-gnu

query stack during panic:
#0 [optimized_mir] optimizing MIR for `<std::hash::random::RandomState as core::default::Default>::default`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
#2 [exported_symbols] collecting exported symbols for crate `0`
end of query stack

Running the build again did not hit the same error.

@alecmocatta
Copy link
Contributor

alecmocatta commented Jun 29, 2024

Ditto, similar ICE compiling a proprietary codebase. This was on CI. Rerunning on the same commit then succeeded.

self.entry(key).and_modify(|old| assert!(*old == value)).or_insert(value);

self.alloc_map.lock().alloc_map.insert_same(id, GlobalAlloc::Memory(mem));

decoder.interner().set_alloc_id_same_memory(alloc_id, alloc);

Details
thread 'rustc' panicked at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/compiler/rustc_data_structures/src/sync.rs:338:42:
assertion failed: *old == value
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/std/src/panicking.rs:661:5
   1: core::panicking::panic_fmt
             at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/panicking.rs:74:14
   2: core::panicking::panic
             at /rustc/9c3bc805dd9cb84019c124b9a50fdff1e62a7ec9/library/core/src/panicking.rs:148:5
   3: <rustc_middle::ty::context::TyCtxt>::set_alloc_id_same_memory
   4: <rustc_metadata::rmeta::decoder::DecodeContext as rustc_type_ir::codec::TyDecoder>::decode_alloc_id
   5: <rustc_middle::mir::syntax::Operand as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode.warm
   6: <rustc_middle::mir::Body as rustc_serialize::serialize::Decodable<rustc_metadata::rmeta::decoder::DecodeContext>>::decode
   7: rustc_metadata::rmeta::decoder::cstore_impl::provide_extern::optimized_mir
      [... omitted 1 frame ...]
   8: <rustc_middle::ty::context::TyCtxt>::instance_mir
   9: <rustc_mir_transform::inline::Inliner>::try_inlining
  10: <rustc_mir_transform::inline::Inliner>::process_blocks
  11: <rustc_mir_transform::inline::Inline as rustc_middle::mir::MirPass>::run_pass
  12: rustc_mir_transform::pass_manager::run_passes_inner
  13: rustc_mir_transform::optimized_mir
      [... omitted 1 frame ...]
  14: rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}
  15: rayon::iter::plumbing::bridge_producer_consumer::helper::<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>
  16: rayon_core::join::join_context::<rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#0}, rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#1}, (), ()>::{closure#0}
  17: rayon::iter::plumbing::bridge_producer_consumer::helper::<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>
  18: rayon_core::join::join_context::<rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#0}, rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#1}, (), ()>::{closure#0}
  19: rayon::iter::plumbing::bridge_producer_consumer::helper::<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>
  20: rayon_core::join::join_context::<rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#0}, rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#1}, (), ()>::{closure#0}
  21: rayon::iter::plumbing::bridge_producer_consumer::helper::<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>
  22: rayon_core::join::join_context::<rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#0}, rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#1}, (), ()>::{closure#0}
  23: rayon::iter::plumbing::bridge_producer_consumer::helper::<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>
  24: rayon_core::join::join_context::<rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#0}, rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#1}, (), ()>::{closure#0}
  25: rayon::iter::plumbing::bridge_producer_consumer::helper::<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>
  26: <rayon_core::job::StackJob<rayon_core::latch::SpinLatch, rayon_core::join::join_context::call_b<(), rayon::iter::plumbing::bridge_producer_consumer::helper<rayon::slice::IterProducer<indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>, rayon::iter::map::MapConsumer<rayon::iter::for_each::ForEachConsumer<rustc_data_structures::sync::parallel::enabled::par_for_each_in<&rustc_span::def_id::LocalDefId, &indexmap::set::IndexSet<rustc_span::def_id::LocalDefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, rustc_metadata::rmeta::encoder::prefetch_mir::{closure#0}>::{closure#0}::{closure#0}>, <indexmap::Bucket<rustc_span::def_id::LocalDefId, ()>>::key_ref>>::{closure#1}>::{closure#0}, ()> as rayon_core::job::Job>::execute
  27: <rayon_core::registry::WorkerThread>::wait_until_cold
  28: <rayon_core::registry::ThreadBuilder>::run
  29: <<crossbeam_utils::thread::ScopedThreadBuilder>::spawn<<rayon_core::ThreadPoolBuilder>::build_scoped<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
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: please make sure that you have updated to the latest nightly

note: please attach the file at `/home/runner/_work/tably/tably/crates/autobahn/rustc-ice-2024-06-29T17_03_15-61567.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C debug-assertions=on -C overflow-checks=off -C strip=debuginfo -Z oom=panic -Z proc-macro-backtrace -Z macro-backtrace -Z threads=8

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `std::collections::hash::map::HashMap::<K, V>::with_capacity`
#1 [optimized_mir] optimizing MIR for `<impl at /home/runner/_work/tably/tably/crates/autobahn/src/lib.rs:43:1: 43:24>::with_capacity`
end of query stack

@saethlin saethlin added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-const-eval Area: constant evaluation (mir interpretation) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Jul 4, 2024
@ChrisDenton
Copy link
Member

ChrisDenton commented Jul 5, 2024

I got an ICE from the OP's code when building tests twice on x86_64-pc-windows-msvc with rustc 1.81.0-nightly (cc8da78 2024-07-04):

ICE
thread 'rustc' panicked at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e\compiler\rustc_data_structures\src\sync.rs:337:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7ff81a02d5a3 - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ff81a02d5a3 - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff81a02d5a3 - std::backtrace::Backtrace::create
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\backtrace.rs:331
   3:     0x7ff81a02d4ea - std::backtrace::Backtrace::force_capture
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\backtrace.rs:312
   4:     0x7fffaadf6545 - memchr
   5:     0x7ff81a04846b - alloc::boxed::impl$50::call
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\alloc\src\boxed.rs:2078
   6:     0x7ff81a04846b - std::panicking::rust_panic_with_hook
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:804
   7:     0x7ff81a04823f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:663
   8:     0x7ff81a04567f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\backtrace.rs:171
   9:     0x7ff81a047e56 - std::panicking::begin_panic_handler
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:661
  10:     0x7ff81a09dd94 - core::panicking::panic_fmt
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\core\src\panicking.rs:74
  11:     0x7ff81a09de3d - core::panicking::panic
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\core\src\panicking.rs:148
  12:     0x7fffa97e46a2 - <rustc_middle[bdeecb11c8336086]::ty::context::TyCtxt>::set_alloc_id_same_memory
  13:     0x7fffa96c89bb - <rustc_metadata[ad750163167944e7]::rmeta::decoder::DecodeContext as rustc_type_ir[9dfd536501306e43]::codec::TyDecoder>::decode_alloc_id
  14:     0x7fffaa8c87a4 - <aho_corasick[a2225782c592e1d2]::util::prefilter::Builder>::build
  15:     0x7fffaa8b4e2e - <aho_corasick[a2225782c592e1d2]::util::prefilter::Builder>::build
  16:     0x7fffaa952003 - <rustc_metadata[ad750163167944e7]::creader::alloc_error_handler_spans::Finder as rustc_ast[652270f71cc1a825]::visit::Visitor>::visit_item
  17:     0x7fffaa3bda13 - rustc_query_impl[ebda40cb8fea939a]::plumbing::query_key_hash_verify_all
  18:     0x7fffaa2ab0ee - rustc_ty_utils[ea289ddf2ac2917d]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  19:     0x7fffa94e7c35 - rustc_query_impl[ebda40cb8fea939a]::query_system
  20:     0x7fffaacd1ff7 - <rustc_middle[bdeecb11c8336086]::ty::context::TyCtxt>::instance_mir
  21:     0x7fffaa857543 - rustc_monomorphize[662a250e8978a8be]::is_call_from_compiler_builtins_to_upstream_monomorphization
  22:     0x7fffaa854e06 - rustc_monomorphize[662a250e8978a8be]::is_call_from_compiler_builtins_to_upstream_monomorphization
  23:     0x7fffaa8564de - rustc_monomorphize[662a250e8978a8be]::is_call_from_compiler_builtins_to_upstream_monomorphization
  24:     0x7fffabf7bcad - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  25:     0x7fffabf85493 - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  26:     0x7fffac6995d9 - <rayon_core[7162302f1ebc8c42]::registry::WorkerThread>::wait_until_cold
  27:     0x7fffac695e41 - <rayon_core[7162302f1ebc8c42]::registry::ThreadBuilder>::run
  28:     0x7fffaadfa03c - memchr
  29:     0x7fffaade96fd - memchr
  30:     0x7fffaadf9959 - memchr
  31:     0x7ff81a05950d - alloc::boxed::impl$48::call_once
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\alloc\src\boxed.rs:2064
  32:     0x7ff81a05950d - alloc::boxed::impl$48::call_once
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\alloc\src\boxed.rs:2064
  33:     0x7ff81a05950d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\pal\windows\thread.rs:52
  34:     0x7ff869a8257d - BaseThreadInitThunk
  35:     0x7ff86b40af28 - RtlUserThreadStart


rustc version: 1.81.0-nightly (cc8da78a0 2024-07-04)
platform: x86_64-pc-windows-msvc

query stack during panic:
#0 [optimized_mir] optimizing MIR for `fastrand::global_rng::i8`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack

@jieyouxu
Copy link
Member

jieyouxu commented Jul 5, 2024

Weirdly, I can't repro:

rustc 1.81.0-nightly (c1b336cb6 2024-06-21): cargo +nightly test twice, no repro
rustc 1.81.0-nightly (cc8da78a0 2024-07-04): cargo +nightly test twice, no repro

rustc 1.81.0-nightly (cc8da78a0 2024-07-04)
binary: rustc
commit-hash: cc8da78a036dc3c15c35a97651b02af9a6d30c1e
commit-date: 2024-07-04
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7

@ChrisDenton
Copy link
Member

I did have to force it to rebuild by touching a file.

@jieyouxu
Copy link
Member

jieyouxu commented Jul 5, 2024

I did have to force it to rebuild by touching a file.

Thanks, that does it for me too:

ICE
   Compiling rantz_random v0.4.5 (E:\Repos\rantz_random)
thread 'rustc' panicked at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e\compiler\rustc_data_structures\src\sync.rs:337:42:
assertion failed: *old == value
stack backtrace:
   0:     0x7ffdfed44d0d - std::backtrace_rs::backtrace::dbghelp64::trace
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\..\..\backtrace\src\backtrace\dbghelp64.rs:91
   1:     0x7ffdfed44d0d - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ffdfed44d0d - std::sys::backtrace::_print_fmt
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\backtrace.rs:68
   3:     0x7ffdfed44d0d - std::sys::backtrace::_print::impl$0::fmt
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\backtrace.rs:44
   4:     0x7ffdfed75399 - core::fmt::rt::Argument::fmt
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\core\src\fmt\rt.rs:173
   5:     0x7ffdfed75399 - core::fmt::write
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\core\src\fmt\mod.rs:1174
   6:     0x7ffdfed3b341 - std::io::Write::write_fmt<std::sys::pal::windows::stdio::Stderr>
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\io\mod.rs:1835
   7:     0x7ffdfed44ae6 - std::sys::backtrace::print
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\backtrace.rs:34
   8:     0x7ffdfed47ce8 - std::panicking::default_hook::closure$1
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:265
   9:     0x7ffdfed47999 - std::panicking::default_hook
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:292
  10:     0x7ffdf1f65c15 - memchr
  11:     0x7ffdfed4846b - alloc::boxed::impl$50::call
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\alloc\src\boxed.rs:2078
  12:     0x7ffdfed4846b - std::panicking::rust_panic_with_hook
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:804
  13:     0x7ffdfed4823f - std::panicking::begin_panic_handler::closure$0
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:663
  14:     0x7ffdfed4567f - std::sys::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure_env$0,never$>
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\backtrace.rs:171
  15:     0x7ffdfed47e56 - std::panicking::begin_panic_handler
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\panicking.rs:661
  16:     0x7ffdfed9dd94 - core::panicking::panic_fmt
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\core\src\panicking.rs:74
  17:     0x7ffdfed9de3d - core::panicking::panic
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\core\src\panicking.rs:148
  18:     0x7ffdf09546a2 - <rustc_middle[bdeecb11c8336086]::ty::context::TyCtxt>::set_alloc_id_same_memory
  19:     0x7ffdf08389bb - <rustc_metadata[ad750163167944e7]::rmeta::decoder::DecodeContext as rustc_type_ir[9dfd536501306e43]::codec::TyDecoder>::decode_alloc_id
  20:     0x7ffdf1a387a4 - <aho_corasick[a2225782c592e1d2]::util::prefilter::Builder>::build
  21:     0x7ffdf1a24e2e - <aho_corasick[a2225782c592e1d2]::util::prefilter::Builder>::build
  22:     0x7ffdf1ac2003 - <rustc_metadata[ad750163167944e7]::creader::alloc_error_handler_spans::Finder as rustc_ast[652270f71cc1a825]::visit::Visitor>::visit_item
  23:     0x7ffdf152da13 - rustc_query_impl[ebda40cb8fea939a]::plumbing::query_key_hash_verify_all
  24:     0x7ffdf141b0ee - rustc_ty_utils[ea289ddf2ac2917d]::ty::self_ty_of_trait_impl_enabling_order_dep_trait_object_hack
  25:     0x7ffdf0657c35 - rustc_query_impl[ebda40cb8fea939a]::query_system
  26:     0x7ffdf1e41ff7 - <rustc_middle[bdeecb11c8336086]::ty::context::TyCtxt>::instance_mir
  27:     0x7ffdf19c7543 - rustc_monomorphize[662a250e8978a8be]::is_call_from_compiler_builtins_to_upstream_monomorphization
  28:     0x7ffdf19c4e06 - rustc_monomorphize[662a250e8978a8be]::is_call_from_compiler_builtins_to_upstream_monomorphization
  29:     0x7ffdf19c64de - rustc_monomorphize[662a250e8978a8be]::is_call_from_compiler_builtins_to_upstream_monomorphization
  30:     0x7ffdf30ebcad - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  31:     0x7ffdf30f01e6 - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  32:     0x7ffdf30ebf68 - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  33:     0x7ffdf30f01e6 - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  34:     0x7ffdf30ebf68 - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  35:     0x7ffdf30f5493 - <gimli[3bdf8dc921b7251b]::write::str::LineStringTable>::get
  36:     0x7ffdf38095d9 - <rayon_core[7162302f1ebc8c42]::registry::WorkerThread>::wait_until_cold
  37:     0x7ffdf3805e41 - <rayon_core[7162302f1ebc8c42]::registry::ThreadBuilder>::run
  38:     0x7ffdf1f6a03c - memchr
  39:     0x7ffdf1f596fd - memchr
  40:     0x7ffdf1f69959 - memchr
  41:     0x7ffdfed5950d - alloc::boxed::impl$48::call_once
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\alloc\src\boxed.rs:2064
  42:     0x7ffdfed5950d - alloc::boxed::impl$48::call_once
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\alloc\src\boxed.rs:2064
  43:     0x7ffdfed5950d - std::sys::pal::windows::thread::impl$0::new::thread_start
                               at /rustc/cc8da78a036dc3c15c35a97651b02af9a6d30c1e/library\std\src\sys\pal\windows\thread.rs:52
  44:     0x7ffe8eee26ad - BaseThreadInitThunk
  45:     0x7ffe8fd6a9f8 - RtlUserThreadStart

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: please make sure that you have updated to the latest nightly

note: please attach the file at `E:\Repos\rantz_random\rustc-ice-2024-07-05T04_25_58-10060.txt` to your bug report

note: compiler flags: --crate-type lib -C opt-level=1 -C embed-bitcode=no -C debuginfo=2 -C debug-assertions=on -C linker=rust-lld.exe -C incremental=[REDACTED] -Z share-generics=n -Z threads=0

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

query stack during panic:
#0 [optimized_mir] optimizing MIR for `fastrand::global_rng::i64`
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: could not compile `rantz_random` (lib)
warning: build failed, waiting for other jobs to finish...

@saethlin saethlin self-assigned this Jul 5, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 5, 2024
@oli-obk oli-obk added E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc labels Jul 5, 2024
@saethlin
Copy link
Member

saethlin commented Jul 5, 2024

I've minimized this as much as I can. It's quite small now, but still requires two crates and for some reason a path dependency doesn't work. https://github.com/saethlin/rantz_random

The main crate is

pub fn random() {
    fastrand::bool()
}

pub fn seed() {
    fastrand::seed();
}

And the fastrand dependency is

std::thread_local! {
    static RNG: () = ();
}

#[inline]
fn with_rng(f: impl FnOnce()) {
    RNG.with(|_| {
        f()
    })
}

#[inline]
pub fn seed() {
    with_rng(|| {});
}

#[inline]
pub fn bool() {
    with_rng(|| {})
}

And you must have:

  • -Zthreads=0 (probably any value other than can work)
  • Incremental compilation enabled
  • The MIR optimizations implied by -Copt-level=2
  • and at least the Cargo flag -j2 (any number of jobs other than 1, so the default on multi-CPU systems is fine).

For me, the build ICEs about 1 in every 10 compilations, but it is of course random.

@saethlin
Copy link
Member

saethlin commented Jul 6, 2024

searched nightlies: from nightly-2024-01-01 to nightly-2024-07-04
regressed nightly: nightly-2024-06-05
searched commit range: 7c52d2d...a330e49
regressed commit: 27529d5

bisected with cargo-bisect-rustc v0.6.9

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2024-01-01 --end=2024-07-04 --script=script 

So that's #125525 which is just a rewrite of the TLS implementation. All that tells me is that the compiler bug here predates that PR.

@saethlin saethlin added 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 Jul 6, 2024
@saethlin
Copy link
Member

saethlin commented Jul 6, 2024

Hunh, the ICE goes away if I add -j1 to the cargo build invocation... That seems bad.

@saethlin
Copy link
Member

saethlin commented Jul 6, 2024

We are interning alloc1 with bytes that are a pointer to alloc2 then trying to re-intern alloc1, but this time it's a pointer to alloc3. But why...

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 7, 2024
Try to fix ICE from re-interning an AllocId with different allocation contents

I'm trying to fix the ICE in rust-lang#126741 and just based on println-debugging this lock scoping looks strange.

r? `@ghost`
@saethlin
Copy link
Member

saethlin commented Jul 7, 2024

Ah! Turning off GVN makes the reproducer go away. That explains why this is being reported now.

@oli-obk
Copy link
Contributor

oli-obk commented Jul 7, 2024

The root cause maybe that alloc id creation is untracked in incremental and only kept sane by stable hashing the GlobalAlloc instead of the raw index. Maybe there are some issues where we somehow leak the actual index

@saethlin
Copy link
Member

saethlin commented Jul 7, 2024

I've further minimized the library crate to this:

const RNG: fn() = || {};

fn with_rng() {
    let _x = &RNG;
}

pub fn seed() {
    with_rng();
}

pub fn bool() {
    with_rng();
}

@saethlin
Copy link
Member

saethlin commented Jul 7, 2024

This bisects to a handful of different commits, depending on what I set the start of the range to. I suspect that's because the reproducer relies on MIR inlining, and sometimes the critical inlining of with_rng() into seed and bool is blocked by query cycle avoidance.

@oli-obk I think this is more likely a race condition causing the incremental compilation decoding process to enter an invalid state. Of course I'm no expert on the code here, but the fact that triggering the crash requires multiple -Zthreads and multiple Cargo --jobs seems to point that way. Though I cannot explain why multiple compilers running at once would be relevant.

In a successful build, we decode alloc1 twice, and both times it contains a pointer to alloc2.

In a crashing build, we decode alloc1 twice, and the first time it contains a pointer to alloc2 and the second time, it contains a pointer to alloc3. In addition, every time we hit this code path, we crash:

// Start decoding concurrently.
sessions.push(self.session_id);
None

... and I've been unable to find any other workload that tickles that line of code.

So based on the available evidence, it looks like this whole concurrent decoding system just doesn't work.

@saethlin saethlin added the A-incr-comp Area: Incremental compilation label Jul 7, 2024
@saethlin
Copy link
Member

saethlin commented Jul 7, 2024

Yes I realize I'm making the very brave assertion that this PR from 6 years ago is buggy: #51060

I created this PR: #127442 which moves the lock scope so that instead of permitting racy decoding, the lock prevents racy decoding. This PR fixes the ICE, but I feel like it breaks the original design of the system. But also it seems to be perf-neutral.

@saethlin saethlin changed the title Compiler panic in fastrand ICE: "assertion failed: *old == value" in optimized + incremental builds Jul 16, 2024
@saethlin saethlin removed the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Jul 16, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 22, 2024
Try to fix ICE from re-interning an AllocId with different allocation contents

As far as I can tell, based on my investigation in rust-lang#126741, the racy decoding scheme implemented here was never fully correct, but the arrangement of Allocations that's required to ICE the compiler requires some very specific MIR optimizations to create. As far as I can tell, GVN likes to create the problematic pattern, which is why we're noticing this problem now.

So the solution here is to not do racy decoding. If two threads race to decoding an AllocId, one of them is going to sit on a lock until the other is done.
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Jul 24, 2024
Try to fix ICE from re-interning an AllocId with different allocation contents

As far as I can tell, based on my investigation in rust-lang/rust#126741, the racy decoding scheme implemented here was never fully correct, but the arrangement of Allocations that's required to ICE the compiler requires some very specific MIR optimizations to create. As far as I can tell, GVN likes to create the problematic pattern, which is why we're noticing this problem now.

So the solution here is to not do racy decoding. If two threads race to decoding an AllocId, one of them is going to sit on a lock until the other is done.
@saethlin
Copy link
Member

Fixed by #127442

lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Jul 28, 2024
Try to fix ICE from re-interning an AllocId with different allocation contents

As far as I can tell, based on my investigation in rust-lang/rust#126741, the racy decoding scheme implemented here was never fully correct, but the arrangement of Allocations that's required to ICE the compiler requires some very specific MIR optimizations to create. As far as I can tell, GVN likes to create the problematic pattern, which is why we're noticing this problem now.

So the solution here is to not do racy decoding. If two threads race to decoding an AllocId, one of them is going to sit on a lock until the other is done.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: constant evaluation (mir interpretation) A-incr-comp Area: Incremental compilation 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

No branches or pull requests

8 participants