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 when trying to compile code with contracts: No HirId for DefId #136683

Closed
tautschnig opened this issue Feb 7, 2025 · 2 comments · Fixed by #136837
Closed

ICE when trying to compile code with contracts: No HirId for DefId #136683

tautschnig opened this issue Feb 7, 2025 · 2 comments · Fixed by #136837
Labels
C-bug Category: This is a bug. F-contracts `#![feature(contracts)]` 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

@tautschnig
Copy link

This is from the CI run over at #136578:

Code

See the diff over at #136578 (the ICE can be found in the CI logs). The problem, however, appears to arise with any contract that I attempt to add to the library. Even the requires clause that involves no function calls like

#[cfg_attr(not(bootstrap), core::contracts::requires(align > 0 && (align & (align - 1)) == 0))]

triggers this ICE.

Meta

rustc --version --verbose:

rustc 1.86.0-nightly (8d4c9b996 2025-02-06) running on x86_64-unknown-linux-gnu

Error output

error: internal compiler error: /checkout/compiler/rustc_middle/src/hir/mod.rs:187:32: No HirId for DefId(0:35480 ~ core[5955]::ptr::alignment::{impl#0}::of::{closure#0})
Backtrace

error: internal compiler error: /checkout/compiler/rustc_middle/src/hir/mod.rs:187:32: No HirId for DefId(0:35480 ~ core[5955]::ptr::alignment::{impl#0}::of::{closure#0})
  
  
  thread 'rustc' panicked at /checkout/compiler/rustc_middle/src/hir/mod.rs:187:32:
  Box<dyn Any>
  stack backtrace:
     0:     0x7fc481494cd1 - <<std[88684d35122519b1]::sys::backtrace::BacktraceLock>::print::DisplayBacktrace as core[15592c06caabf6d5]::fmt::Display>::fmt
     1:     0x7fc4814f26c3 - core[15592c06caabf6d5]::fmt::write
     2:     0x7fc481488509 - <std[88684d35122519b1]::sys::pal::unix::stdio::Stderr as std[88684d35122519b1]::io::Write>::write_fmt
     3:     0x7fc481494b72 - <std[88684d35122519b1]::sys::backtrace::BacktraceLock>::print
     4:     0x7fc4814975c9 - std[88684d35122519b1]::panicking::default_hook::{closure#0}
     5:     0x7fc4814973d8 - std[88684d35122519b1]::panicking::default_hook
     6:     0x7fc47cdba598 - <alloc[8091702729c13d61]::boxed::Box<rustc_driver_impl[ffd03e65eec7750c]::install_ice_hook::{closure#1}> as core[15592c06caabf6d5]::ops::function::Fn<(&dyn for<'a, 'b> core[15592c06caabf6d5]::ops::function::Fn<(&'a std[88684d35122519b1]::panic::PanicHookInfo<'b>,), Output = ()> + core[15592c06caabf6d5]::marker::Send + core[15592c06caabf6d5]::marker::Sync, &std[88684d35122519b1]::panic::PanicHookInfo)>>::call
     7:     0x7fc4814981d3 - std[88684d35122519b1]::panicking::rust_panic_with_hook
     8:     0x7fc480fe8a43 - std[88684d35122519b1]::panicking::begin_panic::<rustc_errors[25d400b26e576ab2]::ExplicitBug>::{closure#0}
     9:     0x7fc480fe80b6 - std[88684d35122519b1]::sys::backtrace::__rust_end_short_backtrace::<std[88684d35122519b1]::panicking::begin_panic<rustc_errors[25d400b26e576ab2]::ExplicitBug>::{closure#0}, !>
    10:     0x7fc47ccbda9d - std[88684d35122519b1]::panicking::begin_panic::<rustc_errors[25d400b26e576ab2]::ExplicitBug>
    11:     0x7fc480fdafe2 - <rustc_errors[25d400b26e576ab2]::diagnostic::BugAbort as rustc_errors[25d400b26e576ab2]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
    12:     0x7fc480d0802e - rustc_middle[227741590ad19286]::util::bug::opt_span_bug_fmt::<rustc_span[7727584330ba466c]::span_encoding::Span>::{closure#0}
    13:     0x7fc480d0764a - rustc_middle[227741590ad19286]::ty::context::tls::with_opt::<rustc_middle[227741590ad19286]::util::bug::opt_span_bug_fmt<rustc_span[7727584330ba466c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
    14:     0x7fc480d075fb - rustc_middle[227741590ad19286]::ty::context::tls::with_context_opt::<rustc_middle[227741590ad19286]::ty::context::tls::with_opt<rustc_middle[227741590ad19286]::util::bug::opt_span_bug_fmt<rustc_span[7727584330ba466c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
    15:     0x7fc47ccaf362 - rustc_middle[227741590ad19286]::util::bug::bug_fmt
    16:     0x7fc47d0408b7 - <rustc_middle[227741590ad19286]::hir::provide::{closure#0} as core[15592c06caabf6d5]::ops::function::FnOnce<(rustc_middle[227741590ad19286]::ty::context::TyCtxt, rustc_span[7727584330ba466c]::def_id::LocalDefId)>>::call_once
    17:     0x7fc47f554365 - rustc_query_impl[c247de45a97e9dd6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c247de45a97e9dd6]::query_impl::local_def_id_to_hir_id::dynamic_query::{closure#2}::{closure#0}, rustc_middle[227741590ad19286]::query::erase::Erased<[u8; 8usize]>>
    18:     0x7fc47f8a2b95 - <rustc_query_impl[c247de45a97e9dd6]::query_impl::local_def_id_to_hir_id::dynamic_query::{closure#2} as core[15592c06caabf6d5]::ops::function::FnOnce<(rustc_middle[227741590ad19286]::ty::context::TyCtxt, rustc_span[7727584330ba466c]::def_id::LocalDefId)>>::call_once
    19:     0x7fc47f4a24eb - rustc_query_system[993bc0b387e802ba]::query::plumbing::try_execute_query::<rustc_query_impl[c247de45a97e9dd6]::DynamicConfig<rustc_data_structures[676ee1dae3e1fd67]::vec_cache::VecCache<rustc_span[7727584330ba466c]::def_id::LocalDefId, rustc_middle[227741590ad19286]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[993bc0b387e802ba]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[c247de45a97e9dd6]::plumbing::QueryCtxt, false>
    20:     0x7fc47f58b1db - rustc_query_impl[c247de45a97e9dd6]::query_impl::local_def_id_to_hir_id::get_query_non_incr::__rust_end_short_backtrace
    21:     0x7fc47d036892 - rustc_middle[227741590ad19286]::query::plumbing::query_get_at::<rustc_data_structures[676ee1dae3e1fd67]::vec_cache::VecCache<rustc_span[7727584330ba466c]::def_id::LocalDefId, rustc_middle[227741590ad19286]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[993bc0b387e802ba]::dep_graph::graph::DepNodeIndex>>
    22:     0x7fc47d040ed9 - <rustc_middle[227741590ad19286]::hir::provide::{closure#4} as core[15592c06caabf6d5]::ops::function::FnOnce<(rustc_middle[227741590ad19286]::ty::context::TyCtxt, rustc_span[7727584330ba466c]::def_id::LocalDefId)>>::call_once
    23:     0x7fc47f562e17 - rustc_query_impl[c247de45a97e9dd6]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[c247de45a97e9dd6]::query_impl::def_span::dynamic_query::{closure#2}::{closure#0}, rustc_middle[227741590ad19286]::query::erase::Erased<[u8; 8usize]>>
    24:     0x7fc47f602059 - <rustc_query_impl[c247de45a97e9dd6]::query_impl::def_span::dynamic_query::{closure#2} as core[15592c06caabf6d5]::ops::function::FnOnce<(rustc_middle[227741590ad19286]::ty::context::TyCtxt, rustc_span[7727584330ba466c]::def_id::DefId)>>::call_once
    25:     0x7fc47f417179 - rustc_query_system[993bc0b387e802ba]::query::plumbing::try_execute_query::<rustc_query_impl[c247de45a97e9dd6]::DynamicConfig<rustc_query_system[993bc0b387e802ba]::query::caches::DefIdCache<rustc_middle[227741590ad19286]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[c247de45a97e9dd6]::plumbing::QueryCtxt, false>
    26:     0x7fc47f7da6de - rustc_query_impl[c247de45a97e9dd6]::query_impl::def_span::get_query_non_incr::__rust_end_short_backtrace
    27:     0x7fc48046f692 - rustc_middle[227741590ad19286]::query::plumbing::query_get_at::<rustc_query_system[993bc0b387e802ba]::query::caches::DefIdCache<rustc_middle[227741590ad19286]::query::erase::Erased<[u8; 8usize]>>>
    28:     0x7fc48047e581 - <rustc_metadata[f75945e5acdf2ef9]::rmeta::encoder::EncodeContext>::encode_def_ids
    29:     0x7fc480476180 - <rustc_metadata[f75945e5acdf2ef9]::rmeta::encoder::EncodeContext>::encode_crate_root
    30:     0x7fc4804855a2 - rustc_metadata[f75945e5acdf2ef9]::rmeta::encoder::encode_metadata
    31:     0x7fc4804c7e7f - rustc_metadata[f75945e5acdf2ef9]::fs::encode_and_write_metadata
    32:     0x7fc47d04e4a2 - <rustc_interface[f69e68f4f27a07a3]::queries::Linker>::codegen_and_build_linker
    33:     0x7fc47cdf54ce - <std[88684d35122519b1]::thread::local::LocalKey<core[15592c06caabf6d5]::cell::Cell<*const ()>>>::with::<rustc_middle[227741590ad19286]::ty::context::tls::enter_context<<rustc_middle[227741590ad19286]::ty::context::GlobalCtxt>::enter<rustc_interface[f69e68f4f27a07a3]::passes::create_and_enter_global_ctxt<core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>, rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>>::{closure#1}, core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>>::{closure#0}, core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>>
    34:     0x7fc47cd73a67 - <rustc_middle[227741590ad19286]::ty::context::TyCtxt>::create_global_ctxt::<core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>, rustc_interface[f69e68f4f27a07a3]::passes::create_and_enter_global_ctxt<core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>, rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
    35:     0x7fc47cdf24b8 - <rustc_interface[f69e68f4f27a07a3]::passes::create_and_enter_global_ctxt<core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>, rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core[15592c06caabf6d5]::ops::function::FnOnce<(&rustc_session[a369b091548ac0b4]::session::Session, rustc_middle[227741590ad19286]::ty::context::CurrentGcx, &std[88684d35122519b1]::sync::once_lock::OnceLock<rustc_middle[227741590ad19286]::ty::context::GlobalCtxt>, &rustc_data_structures[676ee1dae3e1fd67]::sync::worker_local::WorkerLocal<rustc_middle[227741590ad19286]::arena::Arena>, &rustc_data_structures[676ee1dae3e1fd67]::sync::worker_local::WorkerLocal<rustc_hir[c6f90b8f6d1375eb]::Arena>, rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
    36:     0x7fc47cdf096e - rustc_interface[f69e68f4f27a07a3]::passes::create_and_enter_global_ctxt::<core[15592c06caabf6d5]::option::Option<rustc_interface[f69e68f4f27a07a3]::queries::Linker>, rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}::{closure#2}>
    37:     0x7fc47cd9f58e - <scoped_tls[bf7abbac846ce9d2]::ScopedKey<rustc_span[7727584330ba466c]::SessionGlobals>>::set::<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_with_globals<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_pool_with_globals<rustc_interface[f69e68f4f27a07a3]::interface::run_compiler<(), rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
    38:     0x7fc47cdf4050 - rustc_span[7727584330ba466c]::create_session_globals_then::<(), rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_with_globals<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_pool_with_globals<rustc_interface[f69e68f4f27a07a3]::interface::run_compiler<(), rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
    39:     0x7fc47ce14da2 - std[88684d35122519b1]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_with_globals<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_pool_with_globals<rustc_interface[f69e68f4f27a07a3]::interface::run_compiler<(), rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
    40:     0x7fc47ce15cb3 - <<std[88684d35122519b1]::thread::Builder>::spawn_unchecked_<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_with_globals<rustc_interface[f69e68f4f27a07a3]::util::run_in_thread_pool_with_globals<rustc_interface[f69e68f4f27a07a3]::interface::run_compiler<(), rustc_driver_impl[ffd03e65eec7750c]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[15592c06caabf6d5]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
    41:     0x7fc4814a3f25 - <std[88684d35122519b1]::sys::pal::unix::thread::Thread>::new::thread_start
    42:     0x7fc47c06bac3 - <unknown>
    43:     0x7fc47c0fd850 - <unknown>
    44:                0x0 - <unknown>
  
  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
  
  warning: the ICE couldn't be written to `/checkout/rustc-ice-2025-02-06T13_32_06-11878.txt`: Read-only file system (os error 30)
  
  note: rustc 1.86.0-nightly (8d4c9b996 2025-02-06) running on x86_64-unknown-linux-gnu
  
  note: compiler flags: --crate-type lib -C opt-level=3 -C embed-bitcode=no -C codegen-units=1 -C debug-assertions=on -C symbol-mangling-version=v0 -Z unstable-options -Z macro-backtrace -C split-debuginfo=off -C prefer-dynamic -Z inline-mir -Z inline-mir-preserve-debug -Z mir_strip_debuginfo=locals-in-tiny-functions -C link-args=-Wl,-z,origin -C link-args=-Wl,-rpath,$ORIGIN/../lib -C embed-bitcode=yes -C force-frame-pointers=yes -Z crate-attr=doc(html_root_url="https://doc.rust-lang.org/nightly/") -Z binary-dep-depinfo -Z force-unstable-if-unmarked
  
  note: some of the compiler flags provided by cargo are hidden
  
  query stack during panic:
  #0 [local_def_id_to_hir_id] getting HIR ID of `ptr::alignment::<impl at library/core/src/ptr/alignment.rs:23:1: 23:15>::of::{closure#0}`
  #1 [def_span] looking up span for `ptr::alignment::<impl at library/core/src/ptr/alignment.rs:23:1: 23:15>::of::{closure#0}`
  end of query stack
  error: could not compile `core` (lib)

@rustbot label: +F-contracts

@tautschnig tautschnig 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 Feb 7, 2025
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-contracts `#![feature(contracts)]` labels Feb 7, 2025
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 7, 2025
@compiler-errors
Copy link
Member

compiler-errors commented Feb 10, 2025

#136837 fixes this.

One important detail you left out when filing this error report is that the ICE happens on inherent functions, i.e. functions inside of impl blocks. Please be sure to file a complete error repro next time.

jhpratt added a commit to jhpratt/rust that referenced this issue Feb 11, 2025
…ering, r=celinval

Overhaul how contracts are lowered on fn-like bodies

Consolidates all of the contracts lowering logic into `lower_fn_body`, rather than having it be split between `lower_item_kind` and `lower_fn_body`. This should fix rust-lang#136683.

r? celinval
@tautschnig
Copy link
Author

#136837 fixes this.

Thank you!

One important detail you left out when filing this error report is that the ICE happens on inherent functions, i.e. functions inside of impl blocks. Please be sure to file a complete error repro next time.

For my own education and to do better next time: how would I have known that it was being-inside-impl that made all the difference? #136578 always was a full reproducer, but I'm not sure which aspect of it I should have attempted to minimise. Thanks again!

@bors bors closed this as completed in 4ae214b Feb 11, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 11, 2025
Rollup merge of rust-lang#136837 - compiler-errors:contracts-body-lowering, r=celinval

Overhaul how contracts are lowered on fn-like bodies

Consolidates all of the contracts lowering logic into `lower_fn_body`, rather than having it be split between `lower_item_kind` and `lower_fn_body`. This should fix rust-lang#136683.

r? celinval
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. F-contracts `#![feature(contracts)]` 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

Successfully merging a pull request may close this issue.

4 participants