rust-lang / rust-lang/rust

ICE: autodiff: `should not be reachable because we counted the number of activities previously`

Open
#150,326 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug F-autodiff I-ICE T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

snippet:

use std::autodiff::autodiff_reverse;
#[autodiff_reverse(autodiff)]
fn square() -> f64 {}

Version information

rustc 1.94.0-nightly (2ca7bcd03 2025-12-23)
binary: rustc
commit-hash: 2ca7bcd03b87b52f7055a59b817443b0ac4a530d
commit-date: 2025-12-23
host: x86_64-unknown-linux-gnu
release: 1.94.0-nightly
LLVM version: 21.1.8

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error[E0658]: use of unstable library feature `autodiff`
 --> /tmp/icemaker_global_tempdir.4K5QMhZtihrW/rustc_testrunner_tmpdir_reporting.siTQ3hJpQOqm/mvce.rs:2:3
  |
2 | #[autodiff_reverse(autodiff)]
  |   ^^^^^^^^^^^^^^^^
  |
  = note: see issue #124509 <https://github.com/rust-lang/rust/issues/124509> for more information
  = help: add `#![feature(autodiff)]` to the crate attributes to enable
  = note: this compiler was built on 2025-12-23; consider upgrading it if it is out of date


thread 'rustc' (3569141) panicked at /rustc-dev/2ca7bcd03b87b52f7055a59b817443b0ac4a530d/compiler/rustc_builtin_macros/src/autodiff.rs:139:17:
internal error: entered unreachable code: should not be reachable because we counted the number of activities previously
stack backtrace:
   0:     0x7f9378a2c3a3 - <<std[243ef3771c46e43a]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[c088ff38143eb53e]::fmt::Display>::fmt
   1:     0x7f9379010648 - core[c088ff38143eb53e]::fmt::write
   2:     0x7f9378a42af6 - <std[243ef3771c46e43a]::sys::stdio::unix::Stderr as std[243ef3771c46e43a]::io::Write>::write_fmt
   3:     0x7f9378a02b48 - std[243ef3771c46e43a]::panicking::default_hook::{closure#0}
   4:     0x7f9378a20213 - std[243ef3771c46e43a]::panicking::default_hook
   5:     0x7f9377a10d77 - std[243ef3771c46e43a]::panicking::update_hook::<alloc[baa86124b2c3e6f2]::boxed::Box<rustc_driver_impl[e986b619aabff65e]::install_ice_hook::{closure#1}>>::{closure#0}
   6:     0x7f9378a204f2 - std[243ef3771c46e43a]::panicking::panic_with_hook
   7:     0x7f9378a02c3a - std[243ef3771c46e43a]::panicking::panic_handler::{closure#0}
   8:     0x7f93789f9c19 - std[243ef3771c46e43a]::sys::backtrace::__rust_end_short_backtrace::<std[243ef3771c46e43a]::panicking::panic_handler::{closure#0}, !>
   9:     0x7f9378a046fd - __rustc[6d0b6af41dd8415b]::rust_begin_unwind
  10:     0x7f9375be611c - core[c088ff38143eb53e]::panicking::panic_fmt
  11:     0x7f93777a6fd6 - rustc_builtin_macros[c43dc9e402b49fb2]::autodiff::llvm_enzyme::expand_with_mode
  12:     0x7f93777b81f8 - <rustc_builtin_macros[c43dc9e402b49fb2]::autodiff::llvm_enzyme::expand_reverse as rustc_expand[7ba574a324a285b6]::base::MultiItemModifier>::expand
  13:     0x7f937a61a288 - <rustc_expand[7ba574a324a285b6]::expand::MacroExpander>::fully_expand_fragment
  14:     0x7f937a5fec12 - <rustc_expand[7ba574a324a285b6]::expand::MacroExpander>::expand_crate
  15:     0x7f93797715f3 - rustc_interface[577997324878ea43]::passes::configure_and_expand
  16:     0x7f937a21bad8 - rustc_interface[577997324878ea43]::passes::resolver_for_lowering_raw
  17:     0x7f937a21b84d - rustc_query_impl[3af702bc24a35b84]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3af702bc24a35b84]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2}::{closure#0}, rustc_middle[395a2484b1db1a27]::query::erase::Erased<[u8; 16usize]>>
  18:     0x7f937a21b827 - <rustc_query_impl[3af702bc24a35b84]::query_impl::resolver_for_lowering_raw::dynamic_query::{closure#2} as core[c088ff38143eb53e]::ops::function::FnOnce<(rustc_middle[395a2484b1db1a27]::ty::context::TyCtxt, ())>>::call_once
  19:     0x7f937a1cb35f - rustc_query_system[fae14337e0c02060]::query::plumbing::try_execute_query::<rustc_query_impl[3af702bc24a35b84]::DynamicConfig<rustc_query_system[fae14337e0c02060]::query::caches::SingleCache<rustc_middle[395a2484b1db1a27]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[3af702bc24a35b84]::plumbing::QueryCtxt, false>
  20:     0x7f937a1caec4 - rustc_query_impl[3af702bc24a35b84]::query_impl::resolver_for_lowering_raw::get_query_non_incr::__rust_end_short_backtrace
  21:     0x7f937a3a90f8 - <rustc_interface[577997324878ea43]::passes::create_and_enter_global_ctxt<core[c088ff38143eb53e]::option::Option<rustc_interface[577997324878ea43]::queries::Linker>, rustc_driver_impl[e986b619aabff65e]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[c088ff38143eb53e]::ops::function::FnOnce<(&rustc_session[9908f9ef7e13fd8d]::session::Session, rustc_middle[395a2484b1db1a27]::ty::context::CurrentGcx, alloc[baa86124b2c3e6f2]::sync::Arc<rustc_data_structures[75601f20e3d68749]::jobserver::Proxy>, &std[243ef3771c46e43a]::sync::once_lock::OnceLock<rustc_middle[395a2484b1db1a27]::ty::context::GlobalCtxt>, &rustc_data_structures[75601f20e3d68749]::sync::worker_local::WorkerLocal<rustc_middle[395a2484b1db1a27]::arena::Arena>, &rustc_data_structures[75601f20e3d68749]::sync::worker_local::WorkerLocal<rustc_hir[38bedddefeb6b9a6]::Arena>, rustc_driver_impl[e986b619aabff65e]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
  22:     0x7f937a23cc8a - rustc_interface[577997324878ea43]::interface::run_compiler::<(), rustc_driver_impl[e986b619aabff65e]::run_compiler::{closure#0}>::{closure#1}
  23:     0x7f937a18ffce - std[243ef3771c46e43a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[577997324878ea43]::util::run_in_thread_with_globals<rustc_interface[577997324878ea43]::util::run_in_thread_pool_with_globals<rustc_interface[577997324878ea43]::interface::run_compiler<(), rustc_driver_impl[e986b619aabff65e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  24:     0x7f937a18fda0 - <std[243ef3771c46e43a]::thread::lifecycle::spawn_unchecked<rustc_interface[577997324878ea43]::util::run_in_thread_with_globals<rustc_interface[577997324878ea43]::util::run_in_thread_pool_with_globals<rustc_interface[577997324878ea43]::interface::run_compiler<(), rustc_driver_impl[e986b619aabff65e]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[c088ff38143eb53e]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  25:     0x7f937a195b38 - <std[243ef3771c46e43a]::sys::thread::unix::Thread>::new::thread_start
  26:     0x7f9373a9698b - <unknown>
  27:     0x7f9373b1a9cc - <unknown>
  28:                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: please make sure that you have updated to the latest nightly

note: rustc 1.94.0-nightly (2ca7bcd03 2025-12-23) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [resolver_for_lowering_raw] getting the resolver for lowering
end of query stack
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at compiler/rustc_builtin_macros/src/autodiff.rs:139 and reproduce the panic with the provided shouldnotbereachable.rs snippet on the reported nightly. Trace why the unstable autodiff attribute reaches the unreachable branch; done means the reproducer no longer causes an internal compiler panic and reports an appropriate diagnostic or behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.