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: No HirId for DefId #133771

Closed
matthiaskrgr opened this issue Dec 2, 2024 · 7 comments · Fixed by #133779
Closed

ICE: No HirId for DefId #133771

matthiaskrgr opened this issue Dec 2, 2024 · 7 comments · Fixed by #133779
Assignees
Labels
C-bug Category: This is a bug. F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` 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

@matthiaskrgr
Copy link
Member

snippet:

//@compile-flags: --crate-type=lib
#![feature(generic_arg_infer)]
pub fn foo() {
    let s: [u8; 10];
    s = [0; _];
    dbg!(s);
}

Version information

rustc 1.85.0-nightly (d49be02cf 2024-12-02)
binary: rustc
commit-hash: d49be02cf6d2e2a01264fcdef1e20c826710c0f5
commit-date: 2024-12-02
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.4

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zcrate-attr=feature(generic_arg_infer) --crate-type=lib

Program output

error: internal compiler error: /rustc/d49be02cf6d2e2a01264fcdef1e20c826710c0f5/compiler/rustc_middle/src/hir/mod.rs:182:32: No HirId for DefId(0:5 ~ mvce[cd1a]::foo::{constant#1})

thread 'rustc' panicked at /rustc/d49be02cf6d2e2a01264fcdef1e20c826710c0f5/compiler/rustc_middle/src/hir/mod.rs:182:32:
Box<dyn Any>
stack backtrace:
   0:     0x734b34357daa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h118bb846b40b3af7
   1:     0x734b34a13c66 - core::fmt::write::h0b664413a249cd21
   2:     0x734b359d2d91 - std::io::Write::write_fmt::h91044b6829b973ae
   3:     0x734b34357c02 - std::sys::backtrace::BacktraceLock::print::h6b2df9b41787e785
   4:     0x734b3435a10a - std::panicking::default_hook::{{closure}}::h7482aeb499a8273d
   5:     0x734b34359f53 - std::panicking::default_hook::hdf99d9ae25812da6
   6:     0x734b334d07b8 - std[54f89b4ff1b85c84]::panicking::update_hook::<alloc[9f0ac06b652d5e76]::boxed::Box<rustc_driver_impl[f749f8d2537f8c25]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x734b3435a908 - std::panicking::rust_panic_with_hook::h87604e68748e7c6e
   8:     0x734b33505fb1 - std[54f89b4ff1b85c84]::panicking::begin_panic::<rustc_errors[91543cdef5c3a6cd]::ExplicitBug>::{closure#0}
   9:     0x734b334fae76 - std[54f89b4ff1b85c84]::sys::backtrace::__rust_end_short_backtrace::<std[54f89b4ff1b85c84]::panicking::begin_panic<rustc_errors[91543cdef5c3a6cd]::ExplicitBug>::{closure#0}, !>
  10:     0x734b334f7959 - std[54f89b4ff1b85c84]::panicking::begin_panic::<rustc_errors[91543cdef5c3a6cd]::ExplicitBug>
  11:     0x734b3350fff1 - <rustc_errors[91543cdef5c3a6cd]::diagnostic::BugAbort as rustc_errors[91543cdef5c3a6cd]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x734b33afd8e3 - rustc_middle[62e7f217d80f3273]::util::bug::opt_span_bug_fmt::<rustc_span[59605b547c40ee07]::span_encoding::Span>::{closure#0}
  13:     0x734b33ae5d8a - rustc_middle[62e7f217d80f3273]::ty::context::tls::with_opt::<rustc_middle[62e7f217d80f3273]::util::bug::opt_span_bug_fmt<rustc_span[59605b547c40ee07]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x734b33ae5c1b - rustc_middle[62e7f217d80f3273]::ty::context::tls::with_context_opt::<rustc_middle[62e7f217d80f3273]::ty::context::tls::with_opt<rustc_middle[62e7f217d80f3273]::util::bug::opt_span_bug_fmt<rustc_span[59605b547c40ee07]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x734b31d07b00 - rustc_middle[62e7f217d80f3273]::util::bug::bug_fmt
  16:     0x734b34c82197 - rustc_query_impl[cd39566cd4dca284]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[cd39566cd4dca284]::query_impl::local_def_id_to_hir_id::dynamic_query::{closure#2}::{closure#0}, rustc_middle[62e7f217d80f3273]::query::erase::Erased<[u8; 8usize]>>
  17:     0x734b34c81a36 - rustc_query_system[8fafeb9956bbd4fd]::query::plumbing::try_execute_query::<rustc_query_impl[cd39566cd4dca284]::DynamicConfig<rustc_data_structures[e65fb5d2569cb23a]::vec_cache::VecCache<rustc_span[59605b547c40ee07]::def_id::LocalDefId, rustc_middle[62e7f217d80f3273]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[8fafeb9956bbd4fd]::dep_graph::graph::DepNodeIndex>, false, false, false>, rustc_query_impl[cd39566cd4dca284]::plumbing::QueryCtxt, false>
  18:     0x734b34c8148f - rustc_query_impl[cd39566cd4dca284]::query_impl::local_def_id_to_hir_id::get_query_non_incr::__rust_end_short_backtrace
  19:     0x734b3587ebc9 - rustc_middle[62e7f217d80f3273]::query::plumbing::query_get_at::<rustc_data_structures[e65fb5d2569cb23a]::vec_cache::VecCache<rustc_span[59605b547c40ee07]::def_id::LocalDefId, rustc_middle[62e7f217d80f3273]::query::erase::Erased<[u8; 8usize]>, rustc_query_system[8fafeb9956bbd4fd]::dep_graph::graph::DepNodeIndex>>
  20:     0x734b34f72d01 - <rustc_metadata[c3b2ec142e29108]::rmeta::encoder::EncodeContext>::encode_def_ids
  21:     0x734b357aa726 - <rustc_metadata[c3b2ec142e29108]::rmeta::encoder::EncodeContext>::encode_crate_root
  22:     0x734b35cb4c5a - rustc_metadata[c3b2ec142e29108]::rmeta::encoder::encode_metadata
  23:     0x734b35a4ca8a - rustc_metadata[c3b2ec142e29108]::fs::encode_and_write_metadata
  24:     0x734b35a4b7fe - <rustc_interface[4167b42c413e945c]::queries::Linker>::codegen_and_build_linker
  25:     0x734b35a7915a - rustc_interface[4167b42c413e945c]::interface::run_compiler::<core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>, rustc_driver_impl[f749f8d2537f8c25]::run_compiler::{closure#0}>::{closure#1}
  26:     0x734b358df747 - std[54f89b4ff1b85c84]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[4167b42c413e945c]::util::run_in_thread_with_globals<rustc_interface[4167b42c413e945c]::util::run_in_thread_pool_with_globals<rustc_interface[4167b42c413e945c]::interface::run_compiler<core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>, rustc_driver_impl[f749f8d2537f8c25]::run_compiler::{closure#0}>::{closure#1}, core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>>::{closure#0}, core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>>
  27:     0x734b358df3e2 - <<std[54f89b4ff1b85c84]::thread::Builder>::spawn_unchecked_<rustc_interface[4167b42c413e945c]::util::run_in_thread_with_globals<rustc_interface[4167b42c413e945c]::util::run_in_thread_pool_with_globals<rustc_interface[4167b42c413e945c]::interface::run_compiler<core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>, rustc_driver_impl[f749f8d2537f8c25]::run_compiler::{closure#0}>::{closure#1}, core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>>::{closure#0}, core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[f037553049e685e6]::result::Result<(), rustc_span[59605b547c40ee07]::ErrorGuaranteed>>::{closure#1} as core[f037553049e685e6]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  28:     0x734b358deb2b - std::sys::pal::unix::thread::Thread::new::thread_start::h6cdfcb35b2904981
  29:     0x734b2fc6a39d - <unknown>
  30:     0x734b2fcef49c - <unknown>
  31:                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

note: rustc 1.85.0-nightly (d49be02cf 2024-12-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z crate-attr=feature(generic_arg_infer) --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
#0 [local_def_id_to_hir_id] getting HIR ID of `foo::{constant#1}`
end of query stack
error: aborting due to 1 previous error


@rustbot label +F-generic_arg_infer

@matthiaskrgr matthiaskrgr added C-bug Category: This is a bug. F-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` 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 Dec 2, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 2, 2024
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Dec 2, 2024

mvce I guess?

#![feature(generic_arg_infer)]
#![crate_type="lib"]
pub fn main() {
    let s: [u8; 10];
    s = [0; _];
}

I don't understand why this does not crash with just a main and but needs a crate_type = lib..
bisects to #133155 🤔

@jieyouxu
Copy link
Member

jieyouxu commented Dec 2, 2024

I don't understand why this does not crash with just a main and but needs a crate_type = lib.. bisects to #133155 🤔

Missing a main can mask the errors that occur in later stages I suppose

@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 2, 2024

Are you 100% sure that's what it bisects to? #133589 seems more likely or maybe #133468 🤔

@BoxyUwU BoxyUwU self-assigned this Dec 2, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented Dec 2, 2024

Yeah I think this line should not be next_id and should just keep using lower_node_id

@jieyouxu jieyouxu added S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 2, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 3, 2024
…id, r=compiler-errors

Use correct `hir_id` for array const arg infers

Fixes rust-lang#133771

`self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by rust-lang#133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node.

This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :<

cc rust-lang#133589 `@voidc`

r? `@compiler-errors` `@lcnr`
jhpratt added a commit to jhpratt/rust that referenced this issue Dec 3, 2024
…id, r=compiler-errors

Use correct `hir_id` for array const arg infers

Fixes rust-lang#133771

`self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by rust-lang#133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node.

This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :<

cc rust-lang#133589 ``@voidc``

r? ``@compiler-errors`` ``@lcnr``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 3, 2024
…id, r=compiler-errors

Use correct `hir_id` for array const arg infers

Fixes rust-lang#133771

`self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by rust-lang#133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node.

This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :<

cc rust-lang#133589 ```@voidc```

r? ```@compiler-errors``` ```@lcnr```
@matthiaskrgr
Copy link
Member Author

ah yes I just saw I forgot to revert changes from my bisection script that I did for #133641 which is why other bisections also point to that pr, oops 😅

@matthiaskrgr
Copy link
Member Author

yes this bisects to #133589 :)

@matthiaskrgr
Copy link
Member Author

ah fun, we actually have a test tests/ui/pattern/slice-array-infer.rs that WOULD have exhibited the ICE if compiled with --crate-type lib 🙃

@bors bors closed this as completed in c80286d Dec 3, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 3, 2024
Rollup merge of rust-lang#133779 - BoxyUwU:array_const_arg_infer_hir_id, r=compiler-errors

Use correct `hir_id` for array const arg infers

Fixes rust-lang#133771

`self.next_id()` results in the `DefId` for the const argument, created from the hack introduced by rust-lang#133468, having no `HirId` associated with it. This then results in an ICE in metadata encoding. Fixing this then results in *another* ICE where `encode_defs` was not skipping encoding `type_of` and other queries for `DefId`s when they correspond to a `ConstArgKind::Infer` node.

This only reproduces with a library crate as metadata is not encoded for binaries, and apparently we had 0 tests for `generic_arg_infer` for array lengths in a library crate so this was not caught :<

cc rust-lang#133589 `@voidc`

r? `@compiler-errors` `@lcnr`
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-generic_arg_infer Using `_` as a const argument: #![feature(generic_arg_infer)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants