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: failed to get layout #111176

Closed
matthiaskrgr opened this issue May 4, 2023 · 9 comments · Fixed by #111580
Closed

ICE: failed to get layout #111176

matthiaskrgr opened this issue May 4, 2023 · 9 comments · Fixed by #111580
Assignees
Labels
C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. glacier ICE tracked in rust-lang/glacier. 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

@matthiaskrgr
Copy link
Member

matthiaskrgr commented May 4, 2023

Code

use std::mem;

pub struct S<T: Tr> {
    pub f: <T as Tr>::I,
}

pub trait Tr {
   type I: Tr;
}

impl<T: Tr> Tr for S<T> {
    type I = S<S<T>>;
}

impl Tr for () {
    type I = ();
}

fn foo<T: Tr>() -> usize {
    mem::size_of::<S<T>>()
}

fn main() {
    println!("{}", foo::<S<()>>());
}

Meta

rustc --version --verbose:

<version>

Error output

<output>
Backtrace

error[E0391]: cycle detected when computing layout of `S<S<()>>`
  |
  = note: ...which requires computing layout of `<S<()> as Tr>::I`...
  = note: ...which again requires computing layout of `S<S<()>>`, completing the cycle

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:974:13: failed to get layout for `S<S<()>>`: a cycle occurred during layout computation

thread 'rustc' panicked at 'Box<dyn Any>', /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/compiler/rustc_errors/src/lib.rs:994:33
stack backtrace:
   0:     0x7f4c65369441 - std::backtrace_rs::backtrace::libunwind::trace::hb9be772067563b53
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f4c65369441 - std::backtrace_rs::backtrace::trace_unsynchronized::h031da30dc183647f
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f4c65369441 - std::sys_common::backtrace::_print_fmt::h71eced90df8827aa
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f4c65369441 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hae72971f9b1c0375
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f4c653ca0df - core::fmt::rt::Argument::fmt::h8155c503d36c9b86
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/core/src/fmt/rt.rs:138:9
   5:     0x7f4c653ca0df - core::fmt::write::hbbb4251c2513c3ef
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f4c6535c591 - std::io::Write::write_fmt::hdcff7ff4dad8c59b
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/io/mod.rs:1712:15
   7:     0x7f4c65369255 - std::sys_common::backtrace::_print::hb8bd80d5dffe8016
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f4c65369255 - std::sys_common::backtrace::print::hd57b6e007b7d9859
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f4c6536bee7 - std::panicking::default_hook::{{closure}}::h92b5b1db37900f49
  10:     0x7f4c6536bcd4 - std::panicking::default_hook::h33b32947a165ebfe
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/panicking.rs:288:9
  11:     0x7f4c685707b5 - <rustc_driver_impl[2c3cd2b22615ac74]::DEFAULT_HOOK::{closure#0}::{closure#0} as core[65ac48eb02ee08bd]::ops::function::FnOnce<(&core[65ac48eb02ee08bd]::panic::panic_info::PanicInfo,)>>::call_once::{shim:vtable#0}
  12:     0x7f4c6536c607 - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h65038aad28115701
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/alloc/src/boxed.rs:1999:9
  13:     0x7f4c6536c607 - std::panicking::rust_panic_with_hook::h6818a1a7c65e9cdd
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/panicking.rs:695:13
  14:     0x7f4c68402f91 - std[7223d5cfbaf62610]::panicking::begin_panic::<rustc_errors[eb6afbb30a1cd2c3]::ExplicitBug>::{closure#0}
  15:     0x7f4c68401c26 - std[7223d5cfbaf62610]::sys_common::backtrace::__rust_end_short_backtrace::<std[7223d5cfbaf62610]::panicking::begin_panic<rustc_errors[eb6afbb30a1cd2c3]::ExplicitBug>::{closure#0}, !>
  16:     0x7f4c68401ac6 - std[7223d5cfbaf62610]::panicking::begin_panic::<rustc_errors[eb6afbb30a1cd2c3]::ExplicitBug>
  17:     0x7f4c683f6802 - <rustc_errors[eb6afbb30a1cd2c3]::HandlerInner>::span_bug::<rustc_span[418048bff763fbc6]::span_encoding::Span, alloc[1303c5f908d1c3f4]::string::String>
  18:     0x7f4c683f5f46 - <rustc_errors[eb6afbb30a1cd2c3]::Handler>::span_bug::<rustc_span[418048bff763fbc6]::span_encoding::Span, alloc[1303c5f908d1c3f4]::string::String>
  19:     0x7f4c683faedd - rustc_middle[faa0e51d0d5710e5]::util::bug::opt_span_bug_fmt::<rustc_span[418048bff763fbc6]::span_encoding::Span>::{closure#0}
  20:     0x7f4c683faf0a - rustc_middle[faa0e51d0d5710e5]::ty::context::tls::with_opt::<rustc_middle[faa0e51d0d5710e5]::util::bug::opt_span_bug_fmt<rustc_span[418048bff763fbc6]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0x7f4c683faaba - rustc_middle[faa0e51d0d5710e5]::ty::context::tls::with_context_opt::<rustc_middle[faa0e51d0d5710e5]::ty::context::tls::with_opt<rustc_middle[faa0e51d0d5710e5]::util::bug::opt_span_bug_fmt<rustc_span[418048bff763fbc6]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0x7f4c66d96d44 - rustc_middle[faa0e51d0d5710e5]::util::bug::span_bug_fmt::<rustc_span[418048bff763fbc6]::span_encoding::Span>
  23:     0x7f4c6840d400 - <rustc_codegen_llvm[f6e646cf3297fbe4]::context::CodegenCx as rustc_middle[faa0e51d0d5710e5]::ty::layout::LayoutOfHelpers>::handle_layout_err
  24:     0x7f4c6840d312 - <rustc_codegen_llvm[f6e646cf3297fbe4]::context::CodegenCx as rustc_middle[faa0e51d0d5710e5]::ty::layout::LayoutOf>::spanned_layout_of::{closure#0}
  25:     0x7f4c66db0a4e - <rustc_codegen_llvm[f6e646cf3297fbe4]::context::CodegenCx as rustc_middle[faa0e51d0d5710e5]::ty::layout::LayoutOf>::spanned_layout_of
  26:     0x7f4c66da905f - <rustc_codegen_ssa[ec866eaa3e7fa1d8]::mir::FunctionCx<rustc_codegen_llvm[f6e646cf3297fbe4]::builder::Builder>>::codegen_rvalue_operand
  27:     0x7f4c66d756bc - rustc_codegen_ssa[ec866eaa3e7fa1d8]::mir::codegen_mir::<rustc_codegen_llvm[f6e646cf3297fbe4]::builder::Builder>
  28:     0x7f4c67a12312 - rustc_codegen_llvm[f6e646cf3297fbe4]::base::compile_codegen_unit::module_codegen
  29:     0x7f4c67a11160 - rustc_codegen_llvm[f6e646cf3297fbe4]::base::compile_codegen_unit
  30:     0x7f4c67c55486 - rustc_codegen_ssa[ec866eaa3e7fa1d8]::base::codegen_crate::<rustc_codegen_llvm[f6e646cf3297fbe4]::LlvmCodegenBackend>
  31:     0x7f4c67c54d52 - <rustc_codegen_llvm[f6e646cf3297fbe4]::LlvmCodegenBackend as rustc_codegen_ssa[ec866eaa3e7fa1d8]::traits::backend::CodegenBackend>::codegen_crate
  32:     0x7f4c67803e90 - rustc_interface[145311d2418df64f]::passes::start_codegen
  33:     0x7f4c677fef07 - <rustc_middle[faa0e51d0d5710e5]::ty::context::GlobalCtxt>::enter::<<rustc_interface[145311d2418df64f]::queries::Queries>::ongoing_codegen::{closure#0}::{closure#0}, core[65ac48eb02ee08bd]::result::Result<alloc[1303c5f908d1c3f4]::boxed::Box<dyn core[65ac48eb02ee08bd]::any::Any>, rustc_span[418048bff763fbc6]::ErrorGuaranteed>>
  34:     0x7f4c677fe4e8 - <rustc_interface[145311d2418df64f]::queries::Queries>::ongoing_codegen
  35:     0x7f4c677fdc23 - <rustc_interface[145311d2418df64f]::interface::Compiler>::enter::<rustc_driver_impl[2c3cd2b22615ac74]::run_compiler::{closure#1}::{closure#2}, core[65ac48eb02ee08bd]::result::Result<core[65ac48eb02ee08bd]::option::Option<rustc_interface[145311d2418df64f]::queries::Linker>, rustc_span[418048bff763fbc6]::ErrorGuaranteed>>
  36:     0x7f4c677fb38f - std[7223d5cfbaf62610]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[145311d2418df64f]::util::run_in_thread_pool_with_globals<rustc_interface[145311d2418df64f]::interface::run_compiler<core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>, rustc_driver_impl[2c3cd2b22615ac74]::run_compiler::{closure#1}>::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>
  37:     0x7f4c67e59e9e - <<std[7223d5cfbaf62610]::thread::Builder>::spawn_unchecked_<rustc_interface[145311d2418df64f]::util::run_in_thread_pool_with_globals<rustc_interface[145311d2418df64f]::interface::run_compiler<core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>, rustc_driver_impl[2c3cd2b22615ac74]::run_compiler::{closure#1}>::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[65ac48eb02ee08bd]::result::Result<(), rustc_span[418048bff763fbc6]::ErrorGuaranteed>>::{closure#1} as core[65ac48eb02ee08bd]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  38:     0x7f4c65376ad5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haa143886c5139467
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/alloc/src/boxed.rs:1985:9
  39:     0x7f4c65376ad5 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::ha0b7575cc93abe25
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/alloc/src/boxed.rs:1985:9
  40:     0x7f4c65376ad5 - std::sys::unix::thread::Thread::new::thread_start::ha9600bcb75fadfd8
                               at /rustc/129195f57c02c8a8e4cfc4b766d4ff7a3a837882/library/std/src/sys/unix/thread.rs:108:17
  41:     0x7f4c65112bb5 - <unknown>
  42:     0x7f4c65194d90 - <unknown>
  43:                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: rustc 1.71.0-nightly (129195f57 2023-05-04) running on x86_64-unknown-linux-gnu

query stack during panic:
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.

@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 May 4, 2023
@matthiaskrgr
Copy link
Member Author

Regression in #111097 😅 cc @oli-obk

@oli-obk
Copy link
Contributor

oli-obk commented May 4, 2023

bwahaha, oh yea, code assuming layout computation can't fail... uh... we should change the sites where that happens to calling abort_if_errors instead of bug!

@oli-obk oli-obk added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label May 4, 2023
@matthiaskrgr
Copy link
Member Author

tbh I find it a bit concerning that this did not trigger anything in our ci :/
The code originally is from #22919 which was fixed in 2015

@oli-obk
Copy link
Contributor

oli-obk commented May 4, 2023

Our code coverage of rustc via its test suite is probably not very high in the error cases.

Do you have ideas for changing this fundamentally? I guess step 0 would be to actually generate coverage information

@matthiaskrgr
Copy link
Member Author

hm, ./src/tools/miri/tests/fail/layout_cycle.rs would have failed if we had built it regularly with rustc, I guess the test pr that fixed #22919 could also have added more tests.

@oli-obk
Copy link
Contributor

oli-obk commented May 4, 2023

I guess we could test all miri tests against miri and against rustc

@atsuzaki
Copy link
Contributor

atsuzaki commented May 5, 2023

@rustbot claim

@atsuzaki
Copy link
Contributor

atsuzaki commented May 8, 2023

(I think) this is the trait method that needs to change (most implementors directly return ! or just propagates the LayoutError). I'm not quite sure how to best change this. Perhaps just change it to no return?

/// Helper used for `layout_of`, to adapt `tcx.layout_of(...)` into a
/// `Self::LayoutOfResult` (which does not need to be a `Result<...>`).
///
/// Most `impl`s, which propagate `LayoutError`s, should simply return `err`,
/// but this hook allows e.g. codegen to return only `TyAndLayout` from its
/// `cx.layout_of(...)`, without any `Result<...>` around it to deal with
/// (and any `LayoutError`s are turned into fatal errors or ICEs).
fn handle_layout_err(
&self,
err: LayoutError<'tcx>,
span: Span,
ty: Ty<'tcx>,
) -> <Self::LayoutOfResult as MaybeResult<TyAndLayout<'tcx>>>::Error;
}

@oli-obk
Copy link
Contributor

oli-obk commented May 9, 2023

you can make the ! returners always invoke span_fatal, irrespective of the LayoutError variant.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Jul 14, 2023
@bors bors closed this as completed in 56d7d93 Aug 29, 2023
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Sep 6, 2023
Don't ICE on layout computation failure

Fixes rust-lang#111176 regression.

r? `@oli-obk`
antoyo pushed a commit to antoyo/rust that referenced this issue Oct 9, 2023
Don't ICE on layout computation failure

Fixes rust-lang#111176 regression.

r? `@oli-obk`
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. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. glacier ICE tracked in rust-lang/glacier. 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