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: thir: LocalTableInContext: key not found #123077

Open
matthiaskrgr opened this issue Mar 26, 2024 · 4 comments · May be fixed by #130443
Open

ICE: thir: LocalTableInContext: key not found #123077

matthiaskrgr opened this issue Mar 26, 2024 · 4 comments · May be fixed by #130443
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

use std::arch::x86_64::{__m128, _mm_blend_ps};

pub fn sse41_blend_noinline( ) -> __m128 {
    let f = { |x, y| unsafe {
        _mm_blend_ps(x, y, { |x, y| unsafe })
    }};
    f(x, y)
}


original:

use std::arch::x86_64::{__m128, _mm_blend_ps};

pub fn sse41_blend_noinline( ) -> __m128 {
    let f = { |x, y| unsafe {
        _mm_blend_ps(x, y, { |x, y| unsafe })
    }};
    f(x, y)
}

pub fn main() {}

Version information

rustc 1.79.0-nightly (35936c483 2024-03-25)
binary: rustc
commit-hash: 35936c4839dd272646394779d151e060d0f6b3ac
commit-date: 2024-03-25
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.2

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

Program output

error: expected `{`, found `}`
 --> /tmp/icemaker_global_tempdir.jaXmoMCLgeqT/rustc_testrunner_tmpdir_reporting.sSd9oSx6BE2l/mvce.rs:5:44
  |
5 |         _mm_blend_ps(x, y, { |x, y| unsafe })
  |                              ------ ------ ^ expected `{`
  |                              |      |
  |                              |      while parsing this `unsafe` expression
  |                              while parsing the body of this closure
  |
help: you might have meant to open the body of the closure, instead of enclosing the closure in a block
  |
5 -         _mm_blend_ps(x, y, { |x, y| unsafe })
5 +         _mm_blend_ps(x, y,  |x, y| { unsafe })
  |

error[E0425]: cannot find value `x` in this scope
 --> /tmp/icemaker_global_tempdir.jaXmoMCLgeqT/rustc_testrunner_tmpdir_reporting.sSd9oSx6BE2l/mvce.rs:7:7
  |
7 |     f(x, y)
  |       ^ help: a local variable with a similar name exists: `f`

error[E0425]: cannot find value `y` in this scope
 --> /tmp/icemaker_global_tempdir.jaXmoMCLgeqT/rustc_testrunner_tmpdir_reporting.sSd9oSx6BE2l/mvce.rs:7:10
  |
7 |     f(x, y)
  |          ^ help: a local variable with a similar name exists: `f`

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.jaXmoMCLgeqT/rustc_testrunner_tmpdir_reporting.sSd9oSx6BE2l/mvce.rs:8:2
  |
8 | }
  |  ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.jaXmoMCLgeqT/rustc_testrunner_tmpdir_reporting.sSd9oSx6BE2l/mvce.rs`

thread 'rustc' panicked at compiler/rustc_mir_build/src/thir/cx/mod.rs:80:58:
LocalTableInContext: key not found
stack backtrace:
   0:     0x73247a222fd5 - std::backtrace_rs::backtrace::libunwind::trace::h358d27b0beb91d52
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x73247a222fd5 - std::backtrace_rs::backtrace::trace_unsynchronized::hb23626f2832be2ef
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x73247a222fd5 - std::sys_common::backtrace::_print_fmt::h12a2241e36ed88c8
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x73247a222fd5 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h00f4d0202e49b73c
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x73247a27413b - core::fmt::rt::Argument::fmt::h50b99c7ac9b6f780
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/fmt/rt.rs:142:9
   5:     0x73247a27413b - core::fmt::write::h052bbc034f024029
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/fmt/mod.rs:1153:17
   6:     0x73247a217d6f - std::io::Write::write_fmt::h8a7055241a914793
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/io/mod.rs:1843:15
   7:     0x73247a222dae - std::sys_common::backtrace::_print::hc7429e59d20aef3d
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x73247a222dae - std::sys_common::backtrace::print::h098f1297ce95d7fd
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x73247a225a29 - std::panicking::default_hook::{{closure}}::hfacad2d95a15b54f
  10:     0x73247a225793 - std::panicking::default_hook::h335f6dbc0bdf0870
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:292:9
  11:     0x732476bd127f - std[8986ecfb476bfa7d]::panicking::update_hook::<alloc[d5b01f14e800d591]::boxed::Box<rustc_driver_impl[4b2f8406c0f6a8ac]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x73247a22612c - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h981ebc744fbdca0e
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/alloc/src/boxed.rs:2029:9
  13:     0x73247a22612c - std::panicking::rust_panic_with_hook::h1985d360b67b5f37
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:793:13
  14:     0x73247a225ed6 - std::panicking::begin_panic_handler::{{closure}}::hf64883af21dee792
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:658:13
  15:     0x73247a223499 - std::sys_common::backtrace::__rust_end_short_backtrace::h48fdcafa2a5427ef
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x73247a225c07 - rust_begin_unwind
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/panicking.rs:646:5
  17:     0x73247a2705d6 - core::panicking::panic_fmt::h01c5db37aea323f1
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/panicking.rs:72:14
  18:     0x73247a27078c - core::panicking::panic_display::h10389bf786f46e48
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/panicking.rs:193:5
  19:     0x73247a27037c - core::panicking::panic_str::h841866e0247822cd
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/panicking.rs:168:5
  20:     0x73247a27037c - core::option::expect_failed::h56dab3756fc11b37
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/core/src/option.rs:1994:5
  21:     0x73247841ad99 - rustc_mir_build[dc0b4206fe456e8d]::thir::cx::thir_body
  22:     0x732478419712 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::thir_body::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 16usize]>>
  23:     0x7324782990ed - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::VecCache<rustc_span[ebc71fb0dc5af8f5]::def_id::LocalDefId, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  24:     0x732478298c69 - rustc_query_impl[a0c31ac015223081]::query_impl::thir_body::get_query_non_incr::__rust_end_short_backtrace
  25:     0x7324784204d9 - rustc_mir_build[dc0b4206fe456e8d]::thir::pattern::check_match::check_match
  26:     0x73247841f6bb - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::check_match::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>
  27:     0x7324787ca5bc - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::VecCache<rustc_span[ebc71fb0dc5af8f5]::def_id::LocalDefId, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  28:     0x7324787ca23f - rustc_query_impl[a0c31ac015223081]::query_impl::check_match::get_query_non_incr::__rust_end_short_backtrace
  29:     0x73247840f2f3 - rustc_mir_build[dc0b4206fe456e8d]::build::mir_build
  30:     0x73247840e7a8 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::mir_built::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 8usize]>>
  31:     0x7324781d08b1 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::VecCache<rustc_span[ebc71fb0dc5af8f5]::def_id::LocalDefId, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  32:     0x7324781d048c - rustc_query_impl[a0c31ac015223081]::query_impl::mir_built::get_query_non_incr::__rust_end_short_backtrace
  33:     0x7324787cb348 - rustc_mir_transform[38567eaebfa221d1]::ffi_unwind_calls::has_ffi_unwind_calls
  34:     0x7324787cae57 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::has_ffi_unwind_calls::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>
  35:     0x7324787ca4f9 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::VecCache<rustc_span[ebc71fb0dc5af8f5]::def_id::LocalDefId, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  36:     0x7324787ca195 - rustc_query_impl[a0c31ac015223081]::query_impl::has_ffi_unwind_calls::get_query_non_incr::__rust_end_short_backtrace
  37:     0x732475623973 - rustc_mir_transform[38567eaebfa221d1]::mir_promoted
  38:     0x732478298e1a - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::mir_promoted::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 16usize]>>
  39:     0x7324782990db - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::VecCache<rustc_span[ebc71fb0dc5af8f5]::def_id::LocalDefId, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 16usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  40:     0x732478298d23 - rustc_query_impl[a0c31ac015223081]::query_impl::mir_promoted::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7324781cea10 - rustc_borrowck[bf6c423544e45c9]::mir_borrowck
  42:     0x7324781ce957 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::mir_borrowck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 8usize]>>
  43:     0x7324781d08b1 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::VecCache<rustc_span[ebc71fb0dc5af8f5]::def_id::LocalDefId, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  44:     0x7324781d03cc - rustc_query_impl[a0c31ac015223081]::query_impl::mir_borrowck::get_query_non_incr::__rust_end_short_backtrace
  45:     0x7324784a6f1d - rustc_interface[c38f70925b3e6389]::passes::analysis
  46:     0x7324784a60c7 - rustc_query_impl[a0c31ac015223081]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[a0c31ac015223081]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>
  47:     0x732478da8f03 - rustc_query_system[97bff28321f2bac]::query::plumbing::try_execute_query::<rustc_query_impl[a0c31ac015223081]::DynamicConfig<rustc_query_system[97bff28321f2bac]::query::caches::SingleCache<rustc_middle[b97de266c643709b]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[a0c31ac015223081]::plumbing::QueryCtxt, false>
  48:     0x732478da8c7f - rustc_query_impl[a0c31ac015223081]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  49:     0x732478c8c299 - rustc_interface[c38f70925b3e6389]::interface::run_compiler::<core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>, rustc_driver_impl[4b2f8406c0f6a8ac]::run_compiler::{closure#0}>::{closure#0}
  50:     0x732478d62bd9 - std[8986ecfb476bfa7d]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[c38f70925b3e6389]::util::run_in_thread_with_globals<rustc_interface[c38f70925b3e6389]::util::run_in_thread_pool_with_globals<rustc_interface[c38f70925b3e6389]::interface::run_compiler<core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>, rustc_driver_impl[4b2f8406c0f6a8ac]::run_compiler::{closure#0}>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>
  51:     0x732478d62a06 - <<std[8986ecfb476bfa7d]::thread::Builder>::spawn_unchecked_<rustc_interface[c38f70925b3e6389]::util::run_in_thread_with_globals<rustc_interface[c38f70925b3e6389]::util::run_in_thread_pool_with_globals<rustc_interface[c38f70925b3e6389]::interface::run_compiler<core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>, rustc_driver_impl[4b2f8406c0f6a8ac]::run_compiler::{closure#0}>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[8cbc9b2d85f665a9]::result::Result<(), rustc_span[ebc71fb0dc5af8f5]::ErrorGuaranteed>>::{closure#1} as core[8cbc9b2d85f665a9]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  52:     0x73247a22fa49 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h6dc9de06dfc501ab
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/alloc/src/boxed.rs:2015:9
  53:     0x73247a22fa49 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hc5bbd99ced815c6f
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/alloc/src/boxed.rs:2015:9
  54:     0x73247a22fa49 - std::sys::pal::unix::thread::Thread::new::thread_start::h0243db2ae6ac2b16
                               at /rustc/35936c4839dd272646394779d151e060d0f6b3ac/library/std/src/sys/pal/unix/thread.rs:108:17
  55:     0x732473aa955a - <unknown>
  56:     0x732473b26a3c - <unknown>
  57:                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: rustc 1.79.0-nightly (35936c483 2024-03-25) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [thir_body] building THIR for `sse41_blend_noinline::{closure#0}::{closure#0}`
#1 [check_match] match-checking `sse41_blend_noinline::{closure#0}::{closure#0}`
#2 [mir_built] building MIR for `sse41_blend_noinline::{closure#0}::{closure#0}`
#3 [has_ffi_unwind_calls] checking if `sse41_blend_noinline::{closure#0}::{closure#0}` contains FFI-unwind calls
#4 [mir_promoted] promoting constants in MIR for `sse41_blend_noinline::{closure#0}::{closure#0}`
#5 [mir_borrowck] borrow-checking `sse41_blend_noinline::{closure#0}::{closure#0}`
#6 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0425, E0601.
For more information about an error, try `rustc --explain E0425`.

@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Mar 26, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 26, 2024
@matthiaskrgr
Copy link
Member Author

#120550 cc @oli-obk

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 8, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Apr 15, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 26, 2024

minimal:

fn main() {
    std::arch::x86_64::_mm_blend_ps(loop {}, loop {}, || ());
}

@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 26, 2024

This ICE relies on the stdarch functions because they're annotated with #[rustc_legacy_const_generics]. The attribute rewrites the code from foo(1 + 2) to foo::<{ 1 + 2 }>(). Because of the fact that we only know whether the function argument should be an anon const or not after name resolution, we do not use the DefCollector machinery in rustc_resolve as that runs before nameres.

Typically given some foo::<{ || () }>, in the DefCollector we would create the anon const def, then recurse inside its AST and create the def for the closure with a parent of the anon const. However in the ICEing example we do not know that there should be an anon const when walking the AST and so simply create a def for a closure with as parent of the enclosing main. We then when lowering the function call to hir, create an anon const with the closure inside of it.

Creating an anon const with a closure inside of it that has a parent that is not the anon const then ICEs the compiler at some place later when trying to access typeck information about the closure.

@BoxyUwU BoxyUwU added the A-const-generics Area: const generics (parameters and arguments) label Jun 26, 2024
@BoxyUwU
Copy link
Member

BoxyUwU commented Jun 26, 2024

Regardless of whether #120550 introduced the ice or not, I'm sure this weird parenting behaviour has existed for a long time before hand.

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 16, 2024
…r=<try>

Fix ICE when passing DefId-creating args to legacy_const_generics.

r? BoxyUwU

Fixes rust-lang#123077
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 16, 2024
…r=<try>

Fix ICE when passing DefId-creating args to legacy_const_generics.

r? BoxyUwU

Fixes rust-lang#123077
Fixes rust-lang#129150
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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