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: !base.layout().is_sized() #124436

Open
matthiaskrgr opened this issue Apr 27, 2024 · 1 comment
Open

ICE: !base.layout().is_sized() #124436

matthiaskrgr opened this issue Apr 27, 2024 · 1 comment
Labels
-Zpolymorphize Unstable option: Polymorphization. A-const-eval Area: constant evaluation (mir interpretation) 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):

pub trait TraitCat {}
pub trait TraitDog {}

pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {}

original:

pub struct P;
pub struct R<T>(T);
pub struct R<T>(T);

// in_args test
pub fn alef() -> &'static [R<P>] { T {} }
pub fn epsilon(_x: [R<Q>; 32]) -> R<[Q; 32]> { loop {} }

// in_args test
pub fn alpha(_x: R<&'static [T; 32]>) { loop { loop {} } }
pub fn beta(_x: [T<Q>; 32]) { loop {} }

pub trait TraitCat {}
pub trait TraitDog {}

pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {}

pub fn beta<T: TraitCat + TraitDog>(t: &[Q]) {}

Version information

rustc 1.79.0-nightly (261823eee 2024-04-27)
binary: rustc
commit-hash: 261823eee7021ae24e282e2ca28dbbd3d287b10f
commit-date: 2024-04-27
host: x86_64-unknown-linux-gnu
release: 1.79.0-nightly
LLVM version: 18.1.4

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc -Zdump-mir=all -Zpolymorphize=on

Program output

error[E0601]: `main` function not found in crate `mvce`
 --> /tmp/icemaker_global_tempdir.XYBMwHRwxebv/rustc_testrunner_tmpdir_reporting.AsHkdl3OtxCh/mvce.rs:4:59
  |
4 | pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {}
  |                                                           ^ consider adding a `main` function to `/tmp/icemaker_global_tempdir.XYBMwHRwxebv/rustc_testrunner_tmpdir_reporting.AsHkdl3OtxCh/mvce.rs`

warning: trait objects without an explicit `dyn` are deprecated
 --> /tmp/icemaker_global_tempdir.XYBMwHRwxebv/rustc_testrunner_tmpdir_reporting.AsHkdl3OtxCh/mvce.rs:4:42
  |
4 | pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {}
  |                                          ^^^^^^^^
  |
  = warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
  = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
  = note: `#[warn(bare_trait_objects)]` on by default
help: if this is an object-safe trait, use `dyn`
  |
4 | pub fn gamma<T: TraitCat + TraitDog>(t: [dyn TraitDog; 32]) {}
  |                                          +++

error[E0277]: the size for values of type `(dyn TraitDog + 'static)` cannot be known at compilation time
 --> /tmp/icemaker_global_tempdir.XYBMwHRwxebv/rustc_testrunner_tmpdir_reporting.AsHkdl3OtxCh/mvce.rs:4:41
  |
4 | pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {}
  |                                         ^^^^^^^^^^^^^^ doesn't have a size known at compile-time
  |
  = help: the trait `Sized` is not implemented for `(dyn TraitDog + 'static)`
  = note: slice and array elements must have `Sized` type

warning: unused variable: `t`
 --> /tmp/icemaker_global_tempdir.XYBMwHRwxebv/rustc_testrunner_tmpdir_reporting.AsHkdl3OtxCh/mvce.rs:4:38
  |
4 | pub fn gamma<T: TraitCat + TraitDog>(t: [TraitDog; 32]) {}
  |                                      ^ help: if this is intentional, prefix it with an underscore: `_t`
  |
  = note: `#[warn(unused_variables)]` on by default

thread 'rustc' panicked at compiler/rustc_const_eval/src/interpret/projection.rs:158:13:
assertion failed: !base.layout().is_sized()
stack backtrace:
   0:     0x7cd1f314f015 - std::backtrace_rs::backtrace::libunwind::trace::hb7074df2638d7e84
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/../../backtrace/src/backtrace/libunwind.rs:105:5
   1:     0x7cd1f314f015 - std::backtrace_rs::backtrace::trace_unsynchronized::h70e69390b8223c7c
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7cd1f314f015 - std::sys_common::backtrace::_print_fmt::hfe37e9d78e7e5435
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x7cd1f314f015 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::he8d68a3925434bb5
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7cd1f319e27b - core::fmt::rt::Argument::fmt::h2eb91a7d978fdcfd
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/rt.rs:165:63
   5:     0x7cd1f319e27b - core::fmt::write::h861d74bf08a00cf3
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:1157:21
   6:     0x7cd1f3143bbf - std::io::Write::write_fmt::h85f35fafd21dc258
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/io/mod.rs:1832:15
   7:     0x7cd1f314edee - std::sys_common::backtrace::_print::he8e1fa34d894fbed
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7cd1f314edee - std::sys_common::backtrace::print::h2307b89917ed7766
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7cd1f3151759 - std::panicking::default_hook::{{closure}}::h867d00d7ce9f86ae
  10:     0x7cd1f315149d - std::panicking::default_hook::h5c7e7badcca734ef
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/panicking.rs:298:9
  11:     0x7cd1efa33f6c - std[569c2c2086c9894c]::panicking::update_hook::<alloc[60db01e4fabc4ed5]::boxed::Box<rustc_driver_impl[c1bc4f62c0e337ce]::install_ice_hook::{closure#0}>>::{closure#0}
  12:     0x7cd1f3151e56 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h033bf5b8a4e39f67
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/alloc/src/boxed.rs:2036:9
  13:     0x7cd1f3151e56 - std::panicking::rust_panic_with_hook::h8af2337d7fada5ef
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/panicking.rs:799:13
  14:     0x7cd1f3151bcb - std::panicking::begin_panic_handler::{{closure}}::h9dd247a94cb9a353
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/panicking.rs:656:13
  15:     0x7cd1f314f4d9 - std::sys_common::backtrace::__rust_end_short_backtrace::h8203b00c60fbdb39
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/sys_common/backtrace.rs:171:18
  16:     0x7cd1f3151937 - rust_begin_unwind
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/panicking.rs:652:5
  17:     0x7cd1f319a743 - core::panicking::panic_fmt::h35f546a8bd23ea6e
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/panicking.rs:72:14
  18:     0x7cd1f319a7ec - core::panicking::panic::h44ebe4dfd40269d2
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/panicking.rs:146:5
  19:     0x7cd1f0e88e00 - <rustc_const_eval[e00bb822f5368508]::interpret::eval_context::InterpCx<rustc_const_eval[e00bb822f5368508]::const_eval::machine::CompileTimeInterpreter>>::project_field::<rustc_const_eval[e00bb822f5368508]::interpret::operand::OpTy>
  20:     0x7cd1ef9b608e - <core[3150d8b50ee94ec]::iter::adapters::GenericShunt<core[3150d8b50ee94ec]::iter::adapters::map::Map<core[3150d8b50ee94ec]::ops::range::Range<usize>, rustc_const_eval[e00bb822f5368508]::const_eval::try_destructure_mir_constant_for_user_output::{closure#0}>, core[3150d8b50ee94ec]::option::Option<core[3150d8b50ee94ec]::convert::Infallible>> as core[3150d8b50ee94ec]::iter::traits::iterator::Iterator>::next
  21:     0x7cd1efa06755 - rustc_const_eval[e00bb822f5368508]::const_eval::try_destructure_mir_constant_for_user_output
  22:     0x7cd1efee4d0f - rustc_middle[6a3e410634ca3b5d]::mir::pretty::pretty_print_const_value_tcx
  23:     0x7cd1efed00f9 - <rustc_middle[6a3e410634ca3b5d]::mir::consts::Const as core[3150d8b50ee94ec]::fmt::Display>::fmt
  24:     0x7cd1f319e27b - core::fmt::rt::Argument::fmt::h2eb91a7d978fdcfd
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/rt.rs:165:63
  25:     0x7cd1f319e27b - core::fmt::write::h861d74bf08a00cf3
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:1157:21
  26:     0x7cd1efee89c3 - <rustc_middle[6a3e410634ca3b5d]::mir::VarDebugInfoContents as core[3150d8b50ee94ec]::fmt::Debug>::fmt
  27:     0x7cd1f319e27b - core::fmt::rt::Argument::fmt::h2eb91a7d978fdcfd
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/rt.rs:165:63
  28:     0x7cd1f319e27b - core::fmt::write::h861d74bf08a00cf3
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:1157:21
  29:     0x7cd1efedaf4d - <rustc_middle[6a3e410634ca3b5d]::mir::VarDebugInfo as core[3150d8b50ee94ec]::fmt::Debug>::fmt
  30:     0x7cd1f319e20d - core::fmt::rt::Argument::fmt::h2eb91a7d978fdcfd
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/rt.rs:165:63
  31:     0x7cd1f319e20d - core::fmt::run::hd23c2dc20ef8fca9
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:1207:14
  32:     0x7cd1f319e20d - core::fmt::write::h861d74bf08a00cf3
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:1174:26
  33:     0x7cd1f318e9ab - <&mut W as core::fmt::Write::write_fmt::SpecWriteFmt>::spec_write_fmt::h5b27e4b035fafa5e
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:218:21
  34:     0x7cd1f318e9ab - core::fmt::Write::write_fmt::he542c0aa2d6aa4f9
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/core/src/fmt/mod.rs:223:9
  35:     0x7cd1f318e9ab - alloc::fmt::format::format_inner::h76fdbe8077b86deb
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/alloc/src/fmt.rs:633:16
  36:     0x7cd1efed9b48 - rustc_middle[6a3e410634ca3b5d]::mir::pretty::write_scope_tree
  37:     0x7cd1efedb6a6 - rustc_middle[6a3e410634ca3b5d]::mir::pretty::write_mir_intro
  38:     0x7cd1f003c1c7 - rustc_middle[6a3e410634ca3b5d]::mir::pretty::write_mir_fn::<rustc_mir_transform[341d6274d6eed658]::pass_manager::dump_mir_for_phase_change::{closure#0}>
  39:     0x7cd1f0e027e2 - rustc_mir_transform[341d6274d6eed658]::pass_manager::run_passes_inner
  40:     0x7cd1f160f640 - rustc_mir_transform[341d6274d6eed658]::optimized_mir
  41:     0x7cd1f160e82b - rustc_query_impl[8b44e8a7f8d883bf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8b44e8a7f8d883bf]::query_impl::optimized_mir::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 8usize]>>
  42:     0x7cd1f0e9228e - rustc_query_system[cb6ba9990df42599]::query::plumbing::try_execute_query::<rustc_query_impl[8b44e8a7f8d883bf]::DynamicConfig<rustc_query_system[cb6ba9990df42599]::query::caches::DefIdCache<rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[8b44e8a7f8d883bf]::plumbing::QueryCtxt, false>
  43:     0x7cd1f0e919e6 - rustc_query_impl[8b44e8a7f8d883bf]::query_impl::optimized_mir::get_query_non_incr::__rust_end_short_backtrace
  44:     0x7cd1f1108c56 - rustc_middle[6a3e410634ca3b5d]::query::plumbing::query_get_at::<rustc_query_system[cb6ba9990df42599]::query::caches::DefIdCache<rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 8usize]>>>
  45:     0x7cd1f11232d2 - rustc_query_impl[8b44e8a7f8d883bf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8b44e8a7f8d883bf]::query_impl::unused_generic_params::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 4usize]>>
  46:     0x7cd1f1122a99 - rustc_query_system[cb6ba9990df42599]::query::plumbing::try_execute_query::<rustc_query_impl[8b44e8a7f8d883bf]::DynamicConfig<rustc_query_system[cb6ba9990df42599]::query::caches::DefaultCache<rustc_middle[6a3e410634ca3b5d]::ty::instance::InstanceDef, rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 4usize]>>, false, false, false>, rustc_query_impl[8b44e8a7f8d883bf]::plumbing::QueryCtxt, false>
  47:     0x7cd1f112278e - rustc_query_impl[8b44e8a7f8d883bf]::query_impl::unused_generic_params::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7cd1f111eee6 - rustc_interface[a6e61e277917f284]::passes::analysis
  49:     0x7cd1f111dbd5 - rustc_query_impl[8b44e8a7f8d883bf]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[8b44e8a7f8d883bf]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 1usize]>>
  50:     0x7cd1f1bc6665 - rustc_query_system[cb6ba9990df42599]::query::plumbing::try_execute_query::<rustc_query_impl[8b44e8a7f8d883bf]::DynamicConfig<rustc_query_system[cb6ba9990df42599]::query::caches::SingleCache<rustc_middle[6a3e410634ca3b5d]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[8b44e8a7f8d883bf]::plumbing::QueryCtxt, false>
  51:     0x7cd1f1bc63c9 - rustc_query_impl[8b44e8a7f8d883bf]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  52:     0x7cd1f1a4648e - rustc_interface[a6e61e277917f284]::interface::run_compiler::<core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>, rustc_driver_impl[c1bc4f62c0e337ce]::run_compiler::{closure#0}>::{closure#1}
  53:     0x7cd1f1a34467 - std[569c2c2086c9894c]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a6e61e277917f284]::util::run_in_thread_with_globals<rustc_interface[a6e61e277917f284]::util::run_in_thread_pool_with_globals<rustc_interface[a6e61e277917f284]::interface::run_compiler<core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>, rustc_driver_impl[c1bc4f62c0e337ce]::run_compiler::{closure#0}>::{closure#1}, core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>>::{closure#0}, core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>>
  54:     0x7cd1f1a3422a - <<std[569c2c2086c9894c]::thread::Builder>::spawn_unchecked_<rustc_interface[a6e61e277917f284]::util::run_in_thread_with_globals<rustc_interface[a6e61e277917f284]::util::run_in_thread_pool_with_globals<rustc_interface[a6e61e277917f284]::interface::run_compiler<core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>, rustc_driver_impl[c1bc4f62c0e337ce]::run_compiler::{closure#0}>::{closure#1}, core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>>::{closure#0}, core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[3150d8b50ee94ec]::result::Result<(), rustc_span[6f362a2079b27969]::ErrorGuaranteed>>::{closure#2} as core[3150d8b50ee94ec]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  55:     0x7cd1f315bc8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hec05d78b62dc2056
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/alloc/src/boxed.rs:2022:9
  56:     0x7cd1f315bc8b - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3bd70c017b255ecd
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/alloc/src/boxed.rs:2022:9
  57:     0x7cd1f315bc8b - std::sys::pal::unix::thread::Thread::new::thread_start::haab106638cc78137
                               at /rustc/261823eee7021ae24e282e2ca28dbbd3d287b10f/library/std/src/sys/pal/unix/thread.rs:108:17
  58:     0x7cd1ec8a955a - <unknown>
  59:     0x7cd1ec926a3c - <unknown>
  60:                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: please make sure that you have updated to the latest nightly

note: rustc 1.79.0-nightly (261823eee 2024-04-27) running on x86_64-unknown-linux-gnu

note: compiler flags: -Z dump-mir=all -Z polymorphize=on -Z dump-mir-dir=dir

query stack during panic:
#0 [optimized_mir] optimizing MIR for `gamma`
#1 [unused_generic_params] determining which generic parameters are unused by `gamma`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 2 previous errors; 2 warnings emitted

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

@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. -Zpolymorphize Unstable option: Polymorphization. labels Apr 27, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 27, 2024
@RalfJung
Copy link
Member

RalfJung commented May 6, 2024

This is almost the usual -- code doesn't type check and yet gets fed to the interpreter. Cc @oli-obk @lcnr

However, the twist here is that we're calling the interpreter in dump-mir. In the past I think we made some effort to make dump-mir work even on some invalid data. This is fairly easy for data that's "just" UB but still structurally valid; however, the case here is different. Maybe dump-mir (or try_destructure_mir_constant_for_user_output) should check if the MIR body is involved in type errors, and if it is then avoid calling interpreter methods?

Or alternatively we'll have to carefully audit everything reachable from try_destructure_mir_constant_for_user_output and make it throw_inval! some suitable error that can be ignored further up.

@saethlin saethlin added A-const-eval Area: constant evaluation (mir interpretation) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 9, 2024
@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label May 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-Zpolymorphize Unstable option: Polymorphization. A-const-eval Area: constant evaluation (mir interpretation) 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

No branches or pull requests

4 participants