Skip to content

Creating a recursive type with infinite size leads to ICE #61323

@ackxolotl

Description

@ackxolotl

Creating a recursive type with infinite size by removing a Box leads to an internal compiler error. Might be the same issue as #57373.

To reproduce this bug, run cargo build on this code:

enum A {
    B(C),
}

struct C {
    a: Box<A>,
}

fn main() {

}

Replace Box<A> by A and run cargo build again:

enum A {
    B(C),
}

struct C {
    a: A,
}

fn main() {

}

I expected to see this happen:

error[E0072]: recursive type `A` has infinite size
 --> src/main.rs:1:1
  |
1 | enum A {
  | ^^^^^^ recursive type has infinite size
2 |     B(C),
  |       - recursive without indirection
  |
  = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `A` representable

error[E0072]: recursive type `C` has infinite size
 --> src/main.rs:5:1
  |
5 | struct C {
  | ^^^^^^^^ recursive type has infinite size
6 |     a: A,
  |     ---- recursive without indirection
  |
  = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `C` representable

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0072`.
error: Could not compile `hello_world`.

Instead, this happened:

error: internal compiler error: src/librustc/dep_graph/graph.rs:722: try_mark_previous_green() - Forcing the DepNode should have set its color

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:478
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  15: rustc::dep_graph::graph::DepGraph::try_mark_green
  16: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  17: rustc::ty::AdtDef::sized_constraint_for_ty
  18: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  19: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  20: <T as rustc::ty::context::InternIteratorElement<T,R>>::intern_with
  21: rustc::ty::adt_sized_constraint
  22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::adt_sized_constraint>::compute
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
  25: rustc::ty::query::plumbing::force_from_dep_node
  26: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  27: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  28: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  29: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  30: rustc::dep_graph::graph::DepGraph::try_mark_green
  31: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
  32: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc::hir::itemlikevisit::ParItemLikeVisitor>::visit_item
  33: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  34: rustc_data_structures::sync::par_for_each_in
  35: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:87
  36: rustc::hir::Crate::par_visit_all_item_likes
  37: rustc::util::common::time
  38: rustc_typeck::check_crate
  39: rustc_interface::passes::analysis
  40: rustc::ty::query::__query_compute::analysis
  41: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::analysis>::compute
  42: rustc::dep_graph::graph::DepGraph::with_task_impl
  43: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  44: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  45: rustc_interface::passes::create_global_ctxt::{{closure}}
  46: rustc_interface::interface::run_compiler_in_existing_thread_pool
  47: std::thread::local::LocalKey<T>::with
  48: scoped_tls::ScopedKey<T>::set
  49: syntax::with_globals
query stack during panic:
#0 [adt_sized_constraint] processing `A`
#1 [adt_sized_constraint] processing `C`
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous 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.35.0 (3c235d560 2019-05-20) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `hello_world`.

Meta

rustc --version --verbose:

rustc 1.35.0 (3c235d560 2019-05-20)
binary: rustc
commit-hash: 3c235d5600393dfe6c36eeed34042efad8d4f26e
commit-date: 2019-05-20
host: x86_64-unknown-linux-gnu
release: 1.35.0
LLVM version: 8.0

Activity

added
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
A-incr-compArea: Incremental compilation
on May 29, 2019
pnkfelix

pnkfelix commented on Jun 6, 2019

@pnkfelix
Member

triage: P-high. Removing nomination.

pnkfelix

pnkfelix commented on Jun 6, 2019

@pnkfelix
Member

assigning to @nikomatsakis with expectation that they will delegate.

pnkfelix

pnkfelix commented on Jul 11, 2019

@pnkfelix
Member

nominating to try to find someone to investigate this.

5 remaining items

pnkfelix

pnkfelix commented on Oct 3, 2019

@pnkfelix
Member

triage: Downgrading to P-medium. I still want to resolve this, but it simply does not warrant revisiting every week during T-compiler triage.

added and removed
P-highHigh priority
on Oct 3, 2019
robinmoussu

robinmoussu commented on Nov 17, 2019

@robinmoussu

I encountered the same bug. I starting to create a new issue, but it's exactly the same than this one. In case it's needed, I uploaded the code on this repository on the branch cargo/ICE (there is two commits, the first is fine, the second generate the ICE) in case you want to validate your patch when you will eventually have time to fix it.

added a commit that references this issue on Dec 6, 2019
2a4f638
niklasbuechner

niklasbuechner commented on Dec 30, 2019

@niklasbuechner

I am running into this issue as well. Since the corresponding pr has been merged 24 days ago and the latest version was tagged 14 days ago, I am not sure, if this error should have been fixed with 1.40.0. (I did not find the commit on the master but I am also unsure if it was squashed with other commits.) Therefore, I thought I would at least post my error as well, just in case this is supposed to work.

In my case I have an enum which holds a struct which in turn references that enum. I know that this can't work and I know how the correct way of handling this scenario is, I just wanted to let you know that this crashes the compiler. If you need a more detailed code sample, let me know and I will try to reproduce the error outside of my project.

error: internal compiler error: src/librustc/dep_graph/graph.rs:714: try_mark_previous_green() - Forcing the DepNode should have set its color

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:931:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::begin_panic
   8: rustc_errors::HandlerInner::bug
   9: rustc_errors::Handler::bug
  10: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc::ty::context::tls::with_opt::{{closure}}
  12: rustc::ty::context::tls::with_context_opt
  13: rustc::ty::context::tls::with_opt
  14: rustc::util::bug::opt_span_bug_fmt
  15: rustc::util::bug::bug_fmt
  16: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  17: rustc::dep_graph::graph::DepGraph::try_mark_green
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  19: rustc::ty::AdtDef::sized_constraint_for_ty
  20: <core::iter::adapters::flatten::FlatMap<I,U,F> as core::iter::traits::iterator::Iterator>::next
  21: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  22: <I as rustc::ty::context::InternAs<[T],R>>::intern_with
  23: rustc::ty::adt_sized_constraint
  24: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::adt_sized_constraint>::compute
  25: rustc::dep_graph::graph::DepGraph::with_task_impl
  26: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
  27: rustc::ty::query::plumbing::force_from_dep_node
  28: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  29: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  30: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  31: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  32: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  33: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  34: rustc::dep_graph::graph::DepGraph::try_mark_green
  35: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::ensure_query
  37: __rust_maybe_catch_panic
  38: rustc_data_structures::sync::par_for_each_in
  39: __rust_maybe_catch_panic
  40: rustc::hir::Crate::par_visit_all_item_likes
  41: rustc::util::common::time
  42: rustc_typeck::check_crate
  43: rustc_interface::passes::analysis
  44: rustc::ty::query::__query_compute::analysis
  45: rustc::dep_graph::graph::DepGraph::with_task_impl
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  47: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  48: rustc_interface::passes::create_global_ctxt::{{closure}}
  49: rustc_interface::passes::BoxedGlobalCtxt::enter
  50: rustc_interface::interface::run_compiler_in_existing_thread_pool
  51: std::thread::local::LocalKey<T>::with
  52: scoped_tls::ScopedKey<T>::set
  53: syntax::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.40.0 (73528e339 2019-12-16) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [adt_sized_constraint] processing `ast::comparison::Comparison`
#1 [adt_sized_constraint] processing `ast::expression::Expression`
#2 [analysis] running analysis passes on this crate
end of query stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

A-incr-compArea: Incremental compilationA-type-systemArea: Type systemC-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-mediumMedium priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @nikomatsakis@pnkfelix@aturon@Centril@hellow554

    Issue actions

      Creating a recursive type with infinite size leads to ICE · Issue #61323 · rust-lang/rust