Skip to content

ICE: invalid field type in Immediate::offset: value Scalar(0x0000000000000000) does not match ABI ScalarPair(..) #136442

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

Open
matthiaskrgr opened this issue Feb 2, 2025 · 5 comments
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining 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

matthiaskrgr commented Feb 2, 2025

snippet:

//@compile-flags: -Zmir-enable-passes=+Inline -Zmir-enable-passes=+JumpThreading --crate-type=lib
pub fn problem_thingy(items: &mut impl Iterator<Item = str>) {
    let mut peeker = items.peekable();
    match peeker.peek() {
        Some(_) => (),
        None => return (),
    }
}

Version information

rustc 1.86.0-nightly (6dd75f0d6 2025-02-02)
binary: rustc
commit-hash: 6dd75f0d6802f56564f5f9c947a85ded286d3986
commit-date: 2025-02-02
host: x86_64-unknown-linux-gnu
release: 1.86.0-nightly
LLVM version: 19.1.7

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zmir-enable-passes=+Inline -Zmir-enable-passes=+JumpThreading --crate-type=lib

Program output

error: internal compiler error: /rustc/6dd75f0d6802f56564f5f9c947a85ded286d3986/compiler/rustc_const_eval/src/interpret/operand.rs:157:17: invalid field type in Immediate::offset: value Scalar(0x0000000000000000) does not match ABI ScalarPair(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }, Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }))


thread 'rustc' panicked at /rustc/6dd75f0d6802f56564f5f9c947a85ded286d3986/compiler/rustc_const_eval/src/interpret/operand.rs:157:17:
Box<dyn Any>
stack backtrace:
   0:     0x74a71602ed50 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::hbfd757a12de5328f
   1:     0x74a716814826 - core::fmt::write::h8a36a2b16afbec2c
   2:     0x74a717b39a51 - std::io::Write::write_fmt::h405e3b74afe27f82
   3:     0x74a71602ebb2 - std::sys::backtrace::BacktraceLock::print::h83c9aa10f541661c
   4:     0x74a716031032 - std::panicking::default_hook::{{closure}}::h720ed0d152826500
   5:     0x74a716030eba - std::panicking::default_hook::hfc73f50ca652e2b3
   6:     0x74a715189389 - std[ff511cecd2b9d7cf]::panicking::update_hook::<alloc[c4f21c44eb49384f]::boxed::Box<rustc_driver_impl[b88f56deeb7372ac]::install_ice_hook::{closure#1}>>::{closure#0}
   7:     0x74a716031bb3 - std::panicking::rust_panic_with_hook::h73e8d76e64e48546
   8:     0x74a7151c4051 - std[ff511cecd2b9d7cf]::panicking::begin_panic::<rustc_errors[bb44e506870335f6]::ExplicitBug>::{closure#0}
   9:     0x74a7151b8fc6 - std[ff511cecd2b9d7cf]::sys::backtrace::__rust_end_short_backtrace::<std[ff511cecd2b9d7cf]::panicking::begin_panic<rustc_errors[bb44e506870335f6]::ExplicitBug>::{closure#0}, !>
  10:     0x74a7151b8fad - std[ff511cecd2b9d7cf]::panicking::begin_panic::<rustc_errors[bb44e506870335f6]::ExplicitBug>
  11:     0x74a7151cdfa1 - <rustc_errors[bb44e506870335f6]::diagnostic::BugAbort as rustc_errors[bb44e506870335f6]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x74a7157b3bf3 - rustc_middle[f2fffebf67d4dac6]::util::bug::opt_span_bug_fmt::<rustc_span[4bd220f521370a86]::span_encoding::Span>::{closure#0}
  13:     0x74a71579cb7a - rustc_middle[f2fffebf67d4dac6]::ty::context::tls::with_opt::<rustc_middle[f2fffebf67d4dac6]::util::bug::opt_span_bug_fmt<rustc_span[4bd220f521370a86]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x74a71579ca0b - rustc_middle[f2fffebf67d4dac6]::ty::context::tls::with_context_opt::<rustc_middle[f2fffebf67d4dac6]::ty::context::tls::with_opt<rustc_middle[f2fffebf67d4dac6]::util::bug::opt_span_bug_fmt<rustc_span[4bd220f521370a86]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x74a71394fe70 - rustc_middle[f2fffebf67d4dac6]::util::bug::bug_fmt
  16:     0x74a71823d7cd - <rustc_const_eval[fd121c9846faaa35]::interpret::operand::Immediate>::assert_matches_abi::<rustc_const_eval[fd121c9846faaa35]::interpret::eval_context::InterpCx<rustc_const_eval[fd121c9846faaa35]::const_eval::dummy_machine::DummyMachine>>.cold
  17:     0x74a71734c022 - <rustc_const_eval[fd121c9846faaa35]::interpret::operand::ImmTy>::offset_::<rustc_const_eval[fd121c9846faaa35]::interpret::eval_context::InterpCx<rustc_const_eval[fd121c9846faaa35]::const_eval::dummy_machine::DummyMachine>>
  18:     0x74a71734aa0d - <rustc_const_eval[fd121c9846faaa35]::interpret::operand::OpTy as rustc_const_eval[fd121c9846faaa35]::interpret::projection::Projectable<rustc_middle[f2fffebf67d4dac6]::mir::interpret::pointer::CtfeProvenance>>::offset_with_meta::<rustc_const_eval[fd121c9846faaa35]::const_eval::dummy_machine::DummyMachine>
  19:     0x74a717367411 - <rustc_mir_dataflow[bb806dd31a4a8e17]::value_analysis::Map>::for_each_projection_value::<rustc_const_eval[fd121c9846faaa35]::interpret::operand::OpTy, <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::process_constant::{closure#0}, <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::process_constant::{closure#1}>
  20:     0x74a717363c88 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::process_operand
  21:     0x74a717364283 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::find_opportunity
  22:     0x74a717365407 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::TOFinder>::find_opportunity
  23:     0x74a7173619c4 - <rustc_mir_transform[8d321f23de625b13]::jump_threading::JumpThreading as rustc_mir_transform[8d321f23de625b13]::pass_manager::MirPass>::run_pass
  24:     0x74a7168044a2 - rustc_mir_transform[8d321f23de625b13]::pass_manager::run_passes_inner
  25:     0x74a716d5068e - rustc_mir_transform[8d321f23de625b13]::optimized_mir
  26:     0x74a716d4fe8d - rustc_query_impl[d8c178d2a03c64a0]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d8c178d2a03c64a0]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[f2fffebf67d4dac6]::query::erase::Erased<[u8; 8usize]>>
  27:     0x74a716b30f9f - rustc_query_system[6dc7d387dd994d75]::query::plumbing::try_execute_query::<rustc_query_impl[d8c178d2a03c64a0]::DynamicConfig<rustc_query_system[6dc7d387dd994d75]::query::caches::DefIdCache<rustc_middle[f2fffebf67d4dac6]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d8c178d2a03c64a0]::plumbing::QueryCtxt, false>
  28:     0x74a716b3039f - rustc_query_impl[d8c178d2a03c64a0]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  29:     0x74a71738a6a9 - rustc_middle[f2fffebf67d4dac6]::query::plumbing::query_get_at::<rustc_query_system[6dc7d387dd994d75]::query::caches::DefIdCache<rustc_middle[f2fffebf67d4dac6]::query::erase::Erased<[u8; 8usize]>>>
  30:     0x74a717391a71 - <rustc_metadata[5919056398511050]::rmeta::encoder::EncodeContext>::encode_crate_root
  31:     0x74a71799a468 - rustc_metadata[5919056398511050]::rmeta::encoder::encode_metadata
  32:     0x74a7177bf036 - rustc_metadata[5919056398511050]::fs::encode_and_write_metadata
  33:     0x74a7177bdece - <rustc_interface[2006dbae419e0802]::queries::Linker>::codegen_and_build_linker
  34:     0x74a7177625df - rustc_interface[2006dbae419e0802]::passes::create_and_enter_global_ctxt::<core[27041657fc19ee73]::option::Option<rustc_interface[2006dbae419e0802]::queries::Linker>, rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
  35:     0x74a717741c73 - rustc_interface[2006dbae419e0802]::interface::run_compiler::<(), rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}>::{closure#1}
  36:     0x74a7176a83f5 - std[ff511cecd2b9d7cf]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[2006dbae419e0802]::util::run_in_thread_with_globals<rustc_interface[2006dbae419e0802]::util::run_in_thread_pool_with_globals<rustc_interface[2006dbae419e0802]::interface::run_compiler<(), rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  37:     0x74a7176a80d9 - <<std[ff511cecd2b9d7cf]::thread::Builder>::spawn_unchecked_<rustc_interface[2006dbae419e0802]::util::run_in_thread_with_globals<rustc_interface[2006dbae419e0802]::util::run_in_thread_pool_with_globals<rustc_interface[2006dbae419e0802]::interface::run_compiler<(), rustc_driver_impl[b88f56deeb7372ac]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[27041657fc19ee73]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x74a7176a786b - std::sys::pal::unix::thread::Thread::new::thread_start::hb57557dfe1a8d225
  39:     0x74a7118a339d - <unknown>
  40:     0x74a71192849c - <unknown>
  41:                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.86.0-nightly (6dd75f0d6 2025-02-02) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z mir-enable-passes=+Inline -Z mir-enable-passes=+JumpThreading --crate-type lib -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `problem_thingy`
end of query stack
error: aborting due to 1 previous error


cc #135020

@matthiaskrgr matthiaskrgr 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 2, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Feb 2, 2025
@matthiaskrgr matthiaskrgr added A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 2, 2025
@RalfJung
Copy link
Member

RalfJung commented Feb 4, 2025

This ICEs even without any flags:

error: internal compiler error: encountered unexpected unsized field in layout of std::option::Option<str>: TyAndLayout {
                                    ty: str,
                                    layout: Layout {
                                        size: Size(0 bytes),
                                        align: AbiAndPrefAlign {
                                            abi: Align(1 bytes),
                                            pref: Align(1 bytes),
                                        },
                                        abi: Memory {
                                            sized: false,
                                        },
                                        fields: Array {
                                            stride: Size(1 bytes),
                                            count: 0,
                                        },
                                        largest_niche: None,
                                        variants: Single {
                                            index: 0,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(1 bytes),
                                    },
                                }
  |
  = note: delayed at compiler/rustc_ty_utils/src/layout.rs:109:32 - disabled backtrace

Option<str> is indeed an invalid type so it's not surprising that this leads to ICEs somewhere in the interpreter when working on values of that "type".

Cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented Feb 4, 2025

According to the playground this is fixed on nightly

@RalfJung
Copy link
Member

RalfJung commented Feb 4, 2025

Ah, so ICE in the type system is gone... but it seems like the resulting program is still somehow broken, as it can cause an ICE in MIR opts. Cc @rust-lang/wg-mir-opt

Here's the ICE with debug info and debug assertions (so it fails a bit earlier as we do more consistency checks):

thread 'rustc' panicked at /home/r/src/rust/rustc/compiler/rustc_const_eval/src/interpret/operand.rs:265:9:
immediate Scalar(0x0000000000000000) does not fit to layout TyAndLayout { ty: Option<&str>, layout: Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: ScalarPair(Initialized { value: Pointer(AddressSpace(0)), valid_range: (..=0) | (1..) }, Union { value: Int(I64, false) }), fields: Arbitrary { offsets: [Size(0 bytes)], memory_index: [0] }, largest_niche: None, variants: Multiple { tag: Initialized { value: Pointer(AddressSpace(0)), valid_range: (..=0) | (1..) }, tag_encoding: Niche { untagged_variant: 1, niche_variants: 0..=0, niche_start: 0 }, tag_field: 0, variants: [Layout { size: Size(0 bytes), align: AbiAndPrefAlign { abi: Align(1 bytes), pref: Align(8 bytes) }, abi: Memory { sized: true }, fields: Arbitrary { offsets: [], memory_index: [] }, largest_niche: None, variants: Single { index: 0 }, max_repr_align: None, unadjusted_abi_align: Align(1 bytes), randomization_seed: 2862809314334345461 }, Layout { size: Size(16 bytes), align: AbiAndPrefAlign { abi: Align(8 bytes), pref: Align(8 bytes) }, abi: ScalarPair(Initialized { value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }, Initialized { value: Int(I64, false), valid_range: 0..=18446744073709551615 }), fields: Arbitrary { offsets: [Size(0 bytes)], memory_index: [0] }, largest_niche: Some(Niche { offset: Size(0 bytes), value: Pointer(AddressSpace(0)), valid_range: 1..=18446744073709551615 }), variants: Single { index: 1 }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 2862809314334345477 }] }, max_repr_align: None, unadjusted_abi_align: Align(8 bytes), randomization_seed: 8588427943003036399 } }
stack backtrace:
   0: rust_begin_unwind
             at ./library/std/src/panicking.rs:695:5
   1: core::panicking::panic_fmt
             at ./library/core/src/panicking.rs:75:14
   2: <rustc_const_eval::interpret::operand::ImmTy>::from_immediate
             at ./compiler/rustc_const_eval/src/interpret/operand.rs:265:9
   3: <rustc_const_eval::interpret::operand::OpTy>::as_mplace_or_imm
             at ./compiler/rustc_const_eval/src/interpret/place.rs:320:46
   4: <rustc_const_eval::interpret::operand::OpTy as rustc_const_eval::interpret::projection::Projectable<rustc_middle::mir::interpret::pointer::CtfeProvenance>>::meta
             at ./compiler/rustc_const_eval/src/interpret/operand.rs:521:15
   5: <rustc_const_eval::interpret::eval_context::InterpCx<rustc_const_eval::const_eval::dummy_machine::DummyMachine>>::project_downcast::<rustc_const_eval::interpret::operand::OpTy>
             at ./compiler/rustc_const_eval/src/interpret/projection.rs:208:18
   6: <rustc_mir_transform::jump_threading::TOFinder>::process_constant::{closure#0}
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:397:44
   7: <rustc_mir_dataflow::value_analysis::Map>::for_each_projection_value::<rustc_const_eval::interpret::operand::OpTy, <rustc_mir_transform::jump_threading::TOFinder>::process_constant::{closure#0}, <rustc_mir_transform::jump_threading::TOFinder>::process_constant::{closure#1}>
             at ./compiler/rustc_mir_dataflow/src/value_analysis.rs:778:34
   8: <rustc_mir_transform::jump_threading::TOFinder>::process_constant
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:392:9
   9: <rustc_mir_transform::jump_threading::TOFinder>::process_operand
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:442:17
  10: <rustc_mir_transform::jump_threading::TOFinder>::process_assign
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:462:37
  11: <rustc_mir_transform::jump_threading::TOFinder>::process_statement
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:589:17
  12: <rustc_mir_transform::jump_threading::TOFinder>::find_opportunity::{closure#0}
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:262:13
  13: <rustc_mir_transform::jump_threading::TOFinder>::find_opportunity
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:235:5
  14: <rustc_mir_transform::jump_threading::TOFinder>::recurse_through_terminator::<<rustc_mir_transform::jump_threading::TOFinder>::find_opportunity::{closure#0}::{closure#1}>
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:635:9
  15: <rustc_mir_transform::jump_threading::TOFinder>::find_opportunity::{closure#0}
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:293:17
  16: <rustc_mir_transform::jump_threading::TOFinder>::find_opportunity
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:235:5
  17: <rustc_mir_transform::jump_threading::TOFinder>::start_from_switch
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:230:9
  18: <rustc_mir_transform::jump_threading::JumpThreading as rustc_mir_transform::pass_manager::MirPass>::run_pass
             at ./compiler/rustc_mir_transform/src/jump_threading.rs:93:13
  19: rustc_mir_transform::pass_manager::run_passes_inner
             at ./compiler/rustc_mir_transform/src/pass_manager.rs:291:17
  20: rustc_mir_transform::pass_manager::run_passes
             at ./compiler/rustc_mir_transform/src/pass_manager.rs:199:5
  21: rustc_mir_transform::run_optimization_passes
             at ./compiler/rustc_mir_transform/src/lib.rs:642:5
  22: rustc_mir_transform::inner_optimized_mir
             at ./compiler/rustc_mir_transform/src/lib.rs:762:5
  23: rustc_mir_transform::optimized_mir
             at ./compiler/rustc_mir_transform/src/lib.rs:720:21
  24: rustc_query_impl::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}
             at ./compiler/rustc_query_impl/src/plumbing.rs:280:13
      [... omitted 22 frames ...]
  25: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
             at ./compiler/rustc_middle/src/query/plumbing.rs:181:17
  26: <rustc_middle::query::plumbing::TyCtxtAt>::optimized_mir::<rustc_span::def_id::LocalDefId>
             at ./compiler/rustc_middle/src/query/plumbing.rs:471:31
  27: <rustc_middle::ty::context::TyCtxt>::optimized_mir::<rustc_span::def_id::LocalDefId>
             at ./compiler/rustc_middle/src/query/plumbing.rs:462:17
  28: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_mir
             at ./compiler/rustc_metadata/src/rmeta/encoder.rs:1740:74
  29: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root::{closure#15}
             at ./compiler/rustc_metadata/src/rmeta/encoder.rs:640:29
  30: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
             at ./compiler/rustc_metadata/src/rmeta/encoder.rs:601:27
  31: rustc_metadata::rmeta::encoder::encode_metadata
             at ./compiler/rustc_metadata/src/rmeta/encoder.rs:2337:16
  32: rustc_metadata::fs::encode_and_write_metadata
             at ./compiler/rustc_metadata/src/fs.rs:65:13
  33: rustc_interface::passes::start_codegen
             at ./compiler/rustc_interface/src/passes.rs:1047:44
  34: <rustc_interface::queries::Linker>::codegen_and_build_linker
             at ./compiler/rustc_interface/src/queries.rs:29:31
  35: rustc_driver_impl::run_compiler::{closure#0}::{closure#2}
             at ./compiler/rustc_driver_impl/src/lib.rs:374:18
  36: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}
             at ./compiler/rustc_interface/src/passes.rs:813:27
  37: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}
             at ./compiler/rustc_middle/src/ty/context.rs:1395:37
  38: rustc_middle::ty::context::tls::enter_context::<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}
             at ./compiler/rustc_middle/src/ty/context/tls.rs:72:9
  39: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::try_with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
             at ./library/std/src/thread/local.rs:316:12
  40: <std::thread::local::LocalKey<core::cell::Cell<*const ()>>>::with::<rustc_middle::ty::context::tls::enter_context<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
             at ./library/std/src/thread/local.rs:280:15
  41: rustc_middle::ty::context::tls::enter_context::<<rustc_middle::ty::context::GlobalCtxt>::enter<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>::{closure#1}, core::option::Option<rustc_interface::queries::Linker>>
             at ./compiler/rustc_middle/src/ty/context/tls.rs:69:5
  42: <rustc_middle::ty::context::GlobalCtxt>::enter::<rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}, core::option::Option<rustc_interface::queries::Linker>>
             at ./compiler/rustc_middle/src/ty/context.rs:1395:9
  43: <rustc_middle::ty::context::TyCtxt>::create_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}::{closure#0}>
             at ./compiler/rustc_middle/src/ty/context.rs:1591:9
  44: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2}
             at ./compiler/rustc_interface/src/passes.rs:781:9
  45: <rustc_interface::passes::create_and_enter_global_ctxt<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>::{closure#2} as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once::{shim:vtable#0}
             at ./library/core/src/ops/function.rs:250:5
  46: <alloc::boxed::Box<dyn for<'a> core::ops::function::FnOnce<(&'a rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, &'a std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena<'a>>, &'a rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena<'a>>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}), Output = core::option::Option<rustc_interface::queries::Linker>>> as core::ops::function::FnOnce<(&rustc_session::session::Session, rustc_middle::ty::context::CurrentGcx, &std::sync::once_lock::OnceLock<rustc_middle::ty::context::GlobalCtxt>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_middle::arena::Arena>, &rustc_data_structures::sync::worker_local::WorkerLocal<rustc_hir::Arena>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2})>>::call_once
             at ./library/alloc/src/boxed.rs:2016:9
  47: rustc_interface::passes::create_and_enter_global_ctxt::<core::option::Option<rustc_interface::queries::Linker>, rustc_driver_impl::run_compiler::{closure#0}::{closure#2}>
             at ./compiler/rustc_interface/src/passes.rs:821:5
  48: rustc_driver_impl::run_compiler::{closure#0}
             at ./compiler/rustc_driver_impl/src/lib.rs:339:22
  49: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}
             at ./compiler/rustc_interface/src/interface.rs:509:80
  50: <core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}> as core::ops::function::FnOnce<()>>::call_once
             at ./library/core/src/panic/unwind_safe.rs:272:9
  51: std::panicking::try::do_call::<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>, ()>
             at ./library/std/src/panicking.rs:587:40
  52: std::panicking::try::<(), core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>>
             at ./library/std/src/panicking.rs:550:19
  53: std::panic::catch_unwind::<core::panic::unwind_safe::AssertUnwindSafe<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}::{closure#0}>, ()>
             at ./library/std/src/panic.rs:358:14
  54: rustc_interface::interface::run_compiler::<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
             at ./compiler/rustc_interface/src/interface.rs:509:23
  55: rustc_interface::util::run_in_thread_pool_with_globals::<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}
             at ./compiler/rustc_interface/src/util.rs:175:13
  56: rustc_interface::util::run_in_thread_with_globals::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}
             at ./compiler/rustc_interface/src/util.rs:138:21
  57: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}, ()>
             at /home/r/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/scoped-tls-1.0.1/src/lib.rs:137:9
  58: rustc_span::create_session_globals_then::<(), rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}::{closure#0}>
             at ./compiler/rustc_span/src/lib.rs:139:5
  59: rustc_interface::util::run_in_thread_with_globals::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<(), rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}
             at ./compiler/rustc_interface/src/util.rs:137:17
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Something, somewhere, is creating a value of type Option<&str> that is just a scalar null pointer without metadata. Unsurprisingly, this then explodes a bit later.

@RalfJung
Copy link
Member

RalfJung commented Feb 4, 2025

Adding -Zdump-mir shows some really odd stuff in the post-inlining MIR:

_10 = Option::<Option<str>>::get_or_insert_with::<{closure@Peekable<&mut impl Iterator<Item = str>>::peek::{closure#0}}>(move _11, move _12) -> [return: bb5, unwind continue];

And, I mean Iterator<Item = str> should just be rejected, right? The item type must be sized. It's no surprise later parts of the compiler choke on this.

@RalfJung
Copy link
Member

RalfJung commented Feb 4, 2025

The concrete source of the ICE is this in the post-inlining MIR:

    bb7: {
        _4 = const {transmute(0x0000000000000000): Option<&str>};
        goto -> bb6;
    }

(I had to patch the compiler to make it not ICE when dumping this MIR)

I think this is the None here, which is of type Option<&T>, and since in that context T: Sized, this can be turned into a ptr-sized 0. But later inlining plugs in an unsized T and then 💥

Cc @lcnr @compiler-errors -- the code in the OP used to ICE, this got "fixed" by just accepting the code but that's wrong, it needs to be rejected since it is ill-typed.

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Mar 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations A-mir-opt-inlining Area: MIR inlining 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