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 in Layout::compute with const cycle #44415

Closed
plietar opened this issue Sep 8, 2017 · 3 comments
Closed

ICE in Layout::compute with const cycle #44415

plietar opened this issue Sep 8, 2017 · 3 comments
Labels
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@plietar
Copy link
Contributor

plietar commented Sep 8, 2017

This is a slightly modified version of the compile-fail/const-size_of-cycle test, adding a field at the end of the struct.

#![feature(const_fn)]

struct Foo {
    bytes: [u8; std::mem::size_of::<Foo>()],
    x: usize,
}

fn main() {}

It ends up in the following ICE. The "unsupported cyclic reference between types/traits detected" error is expected.

error[E0391]: unsupported cyclic reference between types/traits detected
  --> src/test/compile-fail/const-size_of-cycle.rs:14:5
   |
14 |     bytes: [u8; std::mem::size_of::<Foo>()],
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic reference
   |
note: the cycle begins when processing `Foo::bytes`...
  --> src/test/compile-fail/const-size_of-cycle.rs:14:5
   |
14 |     bytes: [u8; std::mem::size_of::<Foo>()],
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which then requires const-evaluating `Foo::{{initializer}}`...
  --> src/test/compile-fail/const-size_of-cycle.rs:14:17
   |
14 |     bytes: [u8; std::mem::size_of::<Foo>()],
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
note: ...which then requires computing layout of `Foo`...
   = note: ...which then again requires processing `Foo::bytes`, completing the cycle.

error: internal compiler error: src/librustc/ty/layout.rs:1541: Layout::compute: unexpected type `[type error]`

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.21.0-nightly (97b01abf3 2017-08-31) running on x86_64-apple-darwin

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:492:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
   1: std::panicking::default_hook::{{closure}}
   2: std::panicking::default_hook
   3: std::panicking::rust_panic_with_hook
   4: std::panicking::begin_panic
   5: rustc_errors::Handler::bug
   6: rustc::session::opt_span_bug_fmt::{{closure}}
   7: rustc::session::opt_span_bug_fmt
   8: rustc::session::bug_fmt
   9: rustc::ty::layout::Layout::compute_uncached
  10: rustc::ty::util::layout_raw
  11: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::try_get
  12: rustc::ty::maps::TyCtxtAt::layout_raw
  13: rustc::ty::util::<impl rustc::ty::TyS<'tcx>>::layout
  14: <&'a mut I as core::iter::iterator::Iterator>::next
  15: rustc::ty::layout::Layout::compute_uncached
  16: rustc::ty::util::layout_raw
  17: rustc::ty::maps::<impl rustc::ty::maps::queries::layout_raw<'tcx>>::try_get
  18: rustc::ty::maps::TyCtxtAt::layout_raw
  19: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::layout_raw
  20: rustc_const_eval::eval::eval_const_expr_partial::{{closure}}
  21: rustc_const_eval::eval::eval_const_expr_partial
  22: rustc_const_eval::eval::eval_const_expr_partial
  23: rustc_const_eval::eval::eval_const_expr_partial
  24: rustc_const_eval::eval::eval_const_expr_partial
  25: rustc_const_eval::eval::const_eval
  26: rustc::ty::maps::<impl rustc::ty::maps::queries::const_eval<'tcx>>::try_get
  27: rustc::ty::maps::TyCtxtAt::const_eval
  28: rustc::middle::const_val::eval_length
  29: <rustc_typeck::astconv::AstConv<'gcx, 'tcx> + 'o>::ast_ty_to_ty
  30: rustc_typeck::collect::type_of
  31: rustc::dep_graph::graph::DepGraph::with_task
  32: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check
  33: rustc::ty::maps::<impl rustc::ty::maps::queries::type_of<'tcx>>::try_get
  34: rustc::ty::maps::TyCtxtAt::type_of
  35: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::type_of
  36: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  37: rustc_typeck::check_crate::{{closure}}::{{closure}}
  38: rustc_typeck::check_crate
  39: rustc::ty::context::TyCtxt::create_and_enter
  40: rustc_driver::driver::compile_input
  41: rustc_driver::run_compiler
@alexcrichton alexcrichton 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 Sep 8, 2017
@eminence
Copy link
Contributor

eminence commented Dec 6, 2017

Bug triage: with the current nightly (rustc 1.23.0-nightly (e97ba8328 2017-11-25)), this is no longer an ICE. Instead it yields the expected error:

error[E0391]: unsupported cyclic reference between types/traits detected
    |
note: the cycle begins when computing layout of `Foo`...
note: ...which then requires const-evaluating `Foo::{{initializer}}`...
   --> b.rs:5:17
    |
5   |     bytes: [u8; std::mem::size_of::<Foo>()],
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
    = note: ...which then again requires computing layout of `Foo`, completing the cycle.

error: aborting due to previous error

@arielb1 arielb1 added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Dec 6, 2017
@dsprenkels
Copy link
Contributor

I made a test for this issue. Well, I basically copied @plietar's example and put it in a compile-fail. I opened a PR in #47704.

@dsprenkels
Copy link
Contributor

git bisect suggests this bug was fixed in 622a78c.

dsprenkels pushed a commit to dsprenkels/rust that referenced this issue Jan 30, 2018
kennytm added a commit to kennytm/rust that referenced this issue Feb 5, 2018
Add a regression test for rust-lang#44415

This PR adds a regression test for issue rust-lang#44415.

Fixes rust-lang#44415.
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-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. 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

5 participants