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]: Querying attributes on a constant expression causes assertion failure #128145

Closed
1 of 4 tasks
momvart opened this issue Jul 24, 2024 · 2 comments
Closed
1 of 4 tasks
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@momvart
Copy link
Contributor

momvart commented Jul 24, 2024

I query attributes for any DefId that has a body. Upgrading to the latest nightly version is panicking because a constant expression that is not present in the attributes table is being queried.

Affected release channels

  • Previous Stable
  • Current Stable
  • Current Beta
  • Current Nightly

Rust Version

rustc 1.82.0-nightly (8bfcae730 2024-07-23)
binary: rustc
commit-hash: 8bfcae730a5db2438bbda72796175bba21427be1
commit-date: 2024-07-23
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 18.1.7

Current error output

thread 'rustc' panicked at compiler/rustc_metadata/src/rmeta/decoder.rs:1405:17:
assertion `left == right` failed
  left: AnonConst
 right: Ctor

Backtrace

thread 'rustc' panicked at compiler/rustc_metadata/src/rmeta/decoder.rs:1405:17:
assertion `left == right` failed
  left: AnonConst
 right: Ctor
stack backtrace:
   0:     0x7f5bb2446215 - std::backtrace_rs::backtrace::libunwind::trace::hc100fac9458ea61d
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x7f5bb2446215 - std::backtrace_rs::backtrace::trace_unsynchronized::hef55087fcdadf922
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5bb2446215 - std::sys::backtrace::_print_fmt::h1f2a4053eb374970
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/sys/backtrace.rs:68:9
   3:     0x7f5bb2446215 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hf10c1ebc8bddc711
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/sys/backtrace.rs:41:26
   4:     0x7f5bb2495c8b - core::fmt::rt::Argument::fmt::hdc297574ec01e20b
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/fmt/rt.rs:173:76
   5:     0x7f5bb2495c8b - core::fmt::write::h1b95545231c46caf
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/fmt/mod.rs:1182:21
   6:     0x7f5bb243ad9f - std::io::Write::write_fmt::hb674a7403d96ce62
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/io/mod.rs:1827:15
   7:     0x7f5bb2448a01 - std::sys::backtrace::BacktraceLock::print::h97d31a6209887974
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/sys/backtrace.rs:44:9
   8:     0x7f5bb2448a01 - std::panicking::default_hook::{{closure}}::hed4257fd5a0db25c
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/panicking.rs:269:22
   9:     0x7f5bb24486dc - std::panicking::default_hook::h24ac2f43652a5d56
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/panicking.rs:296:9
  10:     0x7f5bae828dd9 - std[e4b7e4535017d5e1]::panicking::update_hook::<alloc[e6ec1d7ca0a399c5]::boxed::Box<rustc_driver_impl[febec7b9091e9110]::install_ice_hook::{closure#0}>>::{closure#0}
  11:     0x7f5bb24493cf - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h17698a3f854e57f1
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/alloc/src/boxed.rs:2163:9
  12:     0x7f5bb24493cf - std::panicking::rust_panic_with_hook::h1f9833954d467d48
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/panicking.rs:808:13
  13:     0x7f5bb2448ff7 - std::panicking::begin_panic_handler::{{closure}}::h1a936a87dc6e3105
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/panicking.rs:674:13
  14:     0x7f5bb24466d9 - std::sys::backtrace::__rust_end_short_backtrace::hf33c2fe0a2870dfd
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/sys/backtrace.rs:172:18
  15:     0x7f5bb2448c84 - rust_begin_unwind
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/std/src/panicking.rs:665:5
  16:     0x7f5bb2492243 - core::panicking::panic_fmt::he12d0d7468628bb4
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/panicking.rs:74:14
  17:     0x7f5bb249274e - core::panicking::assert_failed_inner::ha97f4fea14e1772c
                               at /rustc/8bfcae730a5db2438bbda72796175bba21427be1/library/core/src/panicking.rs:410:17
  18:     0x7f5baed24f7b - core[54ddcb737db04b55]::panicking::assert_failed::<rustc_hir[1c74cf0c8dec4931]::definitions::DefPathData, rustc_hir[1c74cf0c8dec4931]::definitions::DefPathData>
  19:     0x7f5bb130eebd - <rustc_metadata[91f0e848ebb9135c]::creader::CrateMetadataRef>::get_item_attrs.cold
  20:     0x7f5bb00ff685 - rustc_metadata[91f0e848ebb9135c]::rmeta::decoder::cstore_impl::provide_extern::item_attrs
  21:     0x7f5bb00ff4aa - rustc_query_impl[24355b2398a17e2b]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[24355b2398a17e2b]::query_impl::item_attrs::dynamic_query::{closure#2}::{closure#0}, rustc_middle[fb2b7e38760c264]::query::erase::Erased<[u8; 16usize]>>
  22:     0x7f5bb00ff489 - <rustc_query_impl[24355b2398a17e2b]::query_impl::item_attrs::dynamic_query::{closure#2} as core[54ddcb737db04b55]::ops::function::FnOnce<(rustc_middle[fb2b7e38760c264]::ty::context::TyCtxt, rustc_span[4c8883a1b61e9c8d]::def_id::DefId)>>::call_once
  23:     0x7f5bb032a17a - rustc_query_system[8d1605f3b05757d1]::query::plumbing::try_execute_query::<rustc_query_impl[24355b2398a17e2b]::DynamicConfig<rustc_query_system[8d1605f3b05757d1]::query::caches::DefIdCache<rustc_middle[fb2b7e38760c264]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[24355b2398a17e2b]::plumbing::QueryCtxt, false>
  24:     0x7f5bb03299a3 - rustc_query_impl[24355b2398a17e2b]::query_impl::item_attrs::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7f5bb05ba9f9 - rustc_middle[fb2b7e38760c264]::query::plumbing::query_get_at::<rustc_query_system[8d1605f3b05757d1]::query::caches::DefIdCache<rustc_middle[fb2b7e38760c264]::query::erase::Erased<[u8; 16usize]>>>
  26:     0x7f5bad1991e5 - <rustc_middle[fb2b7e38760c264]::ty::context::TyCtxt>::get_attrs_by_path

Anything else?

The DefId that was given to it:

DefId(1:12582 ~ std[f9c2]::sys::pal::unix::stack_overflow::imp::GUARD::{constant#0})
@momvart momvart 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 Jul 24, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 24, 2024
@momvart
Copy link
Contributor Author

momvart commented Jul 24, 2024

For a fix, I think we can change the assertion to a conditional and return an empty array (default) for any item absent in the table.

fn get_item_attrs(
self,
id: DefIndex,
sess: &'a Session,
) -> impl Iterator<Item = ast::Attribute> + 'a {
self.root
.tables
.attributes
.get(self, id)
.unwrap_or_else(|| {
// Structure and variant constructors don't have any attributes encoded for them,
// but we assume that someone passing a constructor ID actually wants to look at
// the attributes on the corresponding struct or variant.
let def_key = self.def_key(id);
assert_eq!(def_key.disambiguated_data.data, DefPathData::Ctor);
let parent_id = def_key.parent.expect("no parent for a constructor");
self.root
.tables
.attributes
.get(self, parent_id)
.expect("no encoded attributes for a structure or variant")
})
.decode((self, sess))
}

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 25, 2024
@petrochenkov
Copy link
Contributor

Closing #128154 (comment)

@petrochenkov petrochenkov closed this as not planned Won't fix, can't repro, duplicate, stale Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants