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 when getting the size of a struct containing itself in an odd way #82830

Closed
pitust opened this issue Mar 6, 2021 · 5 comments · Fixed by #97398
Closed

ICE when getting the size of a struct containing itself in an odd way #82830

pitust opened this issue Mar 6, 2021 · 5 comments · Fixed by #97398
Labels
A-layout Area: Memory layout of types A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pitust
Copy link

pitust commented Mar 6, 2021

Code

trait A<Y, N> {
    type B;
}
type MaybeBox<T> = <T as A<T, Box<T>>>::B;
struct P {
    t: MaybeBox<P>
}
impl<Y, N> A<Y, N> for P {
    type B = N;
}
fn main() {
    let t: MaybeBox<P>;
}

Meta

rustc --version --verbose:

# nightly
rustc 1.52.0-nightly (9b471a3f5 2021-02-19)
binary: rustc
commit-hash: 9b471a3f5fe57e5c6e08acf665f2094422415a3d
commit-date: 2021-02-19
host: aarch64-apple-darwin
release: 1.52.0-nightly
LLVM version: 11.0.1
# stable
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: aarch64-apple-darwin
release: 1.50.0

Error output

# nightly
warning: unused variable: `t`
  --> src/ice.rs:12:9
   |
12 |     let t: MaybeBox<P>;
   |         ^ help: if this is intentional, prefix it with an underscore: `_t`
   |
   = note: `#[warn(unused_variables)]` on by default

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:778:17: failed to get layout for `Box<P>`: the type `std::alloc::Global` has an unknown layout

thread 'rustc' panicked at 'Box<Any>', /rustc/9b471a3f5fe57e5c6e08acf665f2094422415a3d/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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.52.0-nightly (9b471a3f5 2021-02-19) running on aarch64-apple-darwin

query stack during panic:
end of query stack
error: aborting due to previous error; 1 warning emitted

# stable
warning: unused variable: `t`
  --> src/ice.rs:12:9
   |
12 |     let t: MaybeBox<P>;
   |         ^ help: if this is intentional, prefix it with an underscore: `_t`
   |
   = note: `#[warn(unused_variables)]` on by default

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:896:17: failed to get layout for `Box<P>`: the type `std::alloc::Global` has an unknown layout

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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.50.0 (cb75ad5db 2021-02-10) running on aarch64-apple-darwin

query stack during panic:
end of query stack
error: aborting due to previous error; 1 warning emitted
Backtrace

warning: unused variable: `t`
  --> src/ice.rs:12:9
   |
12 |     let t: MaybeBox<P>;
   |         ^ help: if this is intentional, prefix it with an underscore: `_t`
   |
   = note: `#[warn(unused_variables)]` on by default

error: internal compiler error: compiler/rustc_codegen_llvm/src/context.rs:778:17: failed to get layout for `Box<P>`: the type `std::alloc::Global` has an unknown layout

thread 'rustc' panicked at 'Box<Any>', /rustc/9b471a3f5fe57e5c6e08acf665f2094422415a3d/library/std/src/panic.rs:59:5
stack backtrace:
   0:        0x108462844 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h043213eec1d948a5
   1:        0x1084befc4 - core::fmt::write::hf53968076cf4f14e
   2:        0x108456ad0 - std::io::Write::write_fmt::h28b0246eee567fa4
   3:        0x108466074 - std::panicking::default_hook::{{closure}}::h8d1966a8d6a15176
   4:        0x108465b9c - std::panicking::default_hook::h9e61206a690d3893
   5:        0x101529fc0 - rustc_driver::report_ice::he031b89daf683be2
   6:        0x1084667ac - std::panicking::rust_panic_with_hook::hd1308496ca12fe75
   7:        0x104f815b4 - std::panicking::begin_panic::{{closure}}::hcba543a8c5f1d08d
   8:        0x104f81524 - std::sys_common::backtrace::__rust_end_short_backtrace::h362c2d8a9e8d5298
   9:        0x105331b68 - std::panicking::begin_panic::h93e3158113bdbc60
  10:        0x104f6ff2c - std::panic::panic_any::h726732c1e110a4ed
  11:        0x104f75ed0 - rustc_errors::HandlerInner::bug::h3b8f241f53eaf369
  12:        0x104f74844 - rustc_errors::Handler::bug::h8de1066ed91b927d
  13:        0x104bfaea0 - rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}::h44d18bd8b9b96860
  14:        0x104bfa4f4 - rustc_middle::ty::context::tls::with_opt::{{closure}}::h127e943ea1d82039
  15:        0x104bfa4c4 - rustc_middle::ty::context::tls::with_opt::h15355bc739995ab5
  16:        0x104bfadfc - rustc_middle::util::bug::opt_span_bug_fmt::hd81b691c1ebfe316
  17:        0x10531cf90 - rustc_middle::util::bug::bug_fmt::hed974c89fe586787
  18:        0x101854be4 - <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of::{{closure}}::hc33838b90d61229a
  19:        0x101854ae8 - <rustc_codegen_llvm::context::CodegenCx as rustc_target::abi::LayoutOf>::spanned_layout_of::h1d6e88314f230529
  20:        0x101819b88 - rustc_codegen_ssa::mir::analyze::non_ssa_locals::h7533078a57869e49
  21:        0x1017a7b70 - rustc_codegen_ssa::mir::codegen_mir::he40696223aa51736
  22:        0x1018295e8 - rustc_codegen_ssa::base::codegen_instance::h5db39f5bdef05836
  23:        0x10186bc54 - <rustc_middle::mir::mono::MonoItem as rustc_codegen_ssa::mono_item::MonoItemExt>::define::h46f0ab8e9a6af95e
  24:        0x101766420 - rustc_codegen_llvm::base::compile_codegen_unit::module_codegen::h8383c56c09ee28e5
  25:        0x10187d154 - rustc_query_system::dep_graph::graph::DepGraph<K>::with_task::hb61eed6b6daccc43
  26:        0x101765e54 - rustc_codegen_llvm::base::compile_codegen_unit::hc6ff00cd13bf2ad7
  27:        0x101840568 - <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate::hc0cff821987c1e1a
  28:        0x1016dd278 - rustc_interface::queries::Queries::ongoing_codegen::ha2a71002e07ad1b7
  29:        0x10154aa30 - rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter::h79312bfd55dc88a9
  30:        0x10152c7a4 - rustc_span::with_source_map::h6e88bbd7481b3eff
  31:        0x101543f2c - scoped_tls::ScopedKey<T>::set::hae52353f87af177a
  32:        0x10154ccbc - std::sys_common::backtrace::__rust_begin_short_backtrace::hd3d5294404312cd1
  33:        0x1014e1094 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h6426353783274c03
  34:        0x108472290 - std::sys::unix::thread::Thread::new::thread_start::h5458ae4a1bb3b8f6
  35:        0x1a085e06c - _pthread_kill

note: 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.52.0-nightly (9b471a3f5 2021-02-19) running on aarch64-apple-darwin

query stack during panic:
end of query stack
error: aborting due to previous error; 1 warning emitted

The bug happens in here:

bug!("failed to get layout for `{}`: {}", ty, e)
.

It happens due to an assertion that the error is a LayoutError::SizeOverflow which it isn't i guess.
I think it's related to a type being contained within itself, but not really.

@pitust pitust 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 Mar 6, 2021
@jonas-schievink jonas-schievink added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Mar 6, 2021
@LeSeulArtichaut
Copy link
Contributor

This ICEs since 1.49.0. In 1.48.0, rustc gives the following errors:

rror[E0275]: overflow evaluating the requirement `P: Sized`
 --> <source>:6:8
  |
6 |     t: MaybeBox<P>
  |        ^^^^^^^^^^^
  |
  = note: required because of the requirements on the impl of `A<P, Box<P>>` for `P`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0275`.
ASM generation compiler returned: 1
error[E0275]: overflow evaluating the requirement `P: Sized`
 --> <source>:6:8
  |
6 |     t: MaybeBox<P>
  |        ^^^^^^^^^^^
  |
  = note: required because of the requirements on the impl of `A<P, Box<P>>` for `P`

error: aborting due to previous error

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

@LeSeulArtichaut LeSeulArtichaut added A-layout Area: Memory layout of types regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Mar 6, 2021
@apiraino
Copy link
Contributor

bisection result

searched nightlies: from nightly-2020-08-01 to nightly-2021-03-10
regressed nightly: nightly-2020-10-07
searched commits: from a1dfd24 to 98edd1f
regressed commit: 08e2d46

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2020-08-01 --regress=ice 

@apiraino
Copy link
Contributor

Assigning P-medium as discussed as part of the Prioritization Working Group procedure and removing I-prioritize.

@rustbot label -I-prioritize +P-medium

@rustbot rustbot added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Mar 10, 2021
fanninpm added a commit to fanninpm/glacier that referenced this issue Mar 12, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Mar 12, 2021
@camelid camelid added the A-trait-system Area: Trait system label Mar 22, 2021
@FabianWolff
Copy link
Contributor

Slightly simplified:

trait A<Y> { type B; }
type MaybeBox<T> = <T as A<T>>::B;

struct P { _t: MaybeBox<P> }

impl<Y> A<Y> for P {
    type B = Box<P>;
}

fn main() {
    let _t: MaybeBox<P>;
}

@Alexendoo
Copy link
Member

No longer ICEs since #85868

@Alexendoo Alexendoo added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Sep 4, 2021
JohnTitor added a commit to JohnTitor/rust that referenced this issue May 25, 2022
bors added a commit to rust-lang-ci/rust that referenced this issue May 25, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#97302 (Do writeback of Closure params before visiting the parent expression)
 - rust-lang#97328 (rustc: Fix ICE in native library error reporting)
 - rust-lang#97351 (Output correct type responsible for structural match violation)
 - rust-lang#97398 (Add regression test for rust-lang#82830)
 - rust-lang#97400 (Fix a typo on Struct `Substructure`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in 5d43ae8 May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types A-trait-system Area: Trait system C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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.

9 participants