Skip to content

Recursive type with infinite size leads to internal compiler error (try_mark_green() - Forcing the DepNode should have set its color) #57373

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

Closed
BafDyce opened this issue Jan 6, 2019 · 9 comments
Assignees
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@BafDyce
Copy link

BafDyce commented Jan 6, 2019

A (rather complex) enum-based data structure (code below) lead to the following compiler panic:

$ RUST_BACKTRACE=1 cargo run
   Compiling nested-enums v0.1.0 (file:///home/programmer/programming/rustc-bugs/nested-enums)
error: internal compiler error: src/librustc/dep_graph/graph.rs:634: try_mark_green() - Forcing the DepNode should have set its color

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:590:9
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:70
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:58
             at src/libstd/panicking.rs:200
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:215
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:482
   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_green
  15: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  16: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  17: rustc::ty::AdtDef::sized_constraint
  18: rustc::ty::AdtDef::sized_constraint_for_ty
  19: rustc::ty::AdtDef::sized_constraint_for_ty
  20: <core::iter::FlatMap<I, U, F> as core::iter::iterator::Iterator>::next
  21: <smallvec::SmallVec<A> as core::iter::traits::FromIterator<<A as smallvec::Array>::Item>>::from_iter
  22: <T as rustc::ty::context::InternIteratorElement<T, R>>::intern_with
  23: rustc::ty::adt_sized_constraint
  24: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::adt_sized_constraint<'tcx>>::compute
  25: rustc::dep_graph::graph::DepGraph::with_task_impl
  26: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  28: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query
  29: rustc::ty::query::plumbing::force_from_dep_node
  30: rustc::dep_graph::graph::DepGraph::try_mark_green
  31: rustc::dep_graph::graph::DepGraph::try_mark_green
  32: rustc::dep_graph::graph::DepGraph::try_mark_green
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  35: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt<'cx, 'gcx, 'tcx>>::evaluate_obligation
  36: rustc::traits::query::evaluate_obligation::<impl rustc::infer::InferCtxt<'cx, 'gcx, 'tcx>>::evaluate_obligation_no_overflow
  37: <rustc_data_structures::obligation_forest::ObligationForest<O>>::process_obligations
  38: <rustc::traits::fulfill::FulfillmentContext<'tcx> as rustc::traits::engine::TraitEngine<'tcx>>::select_where_possible
  39: <rustc::traits::fulfill::FulfillmentContext<'tcx> as rustc::traits::engine::TraitEngine<'tcx>>::select_all_or_error
  40: rustc_typeck::check::FnCtxt::select_all_obligations_or_error
  41: rustc::ty::context::GlobalCtxt::enter_local
  42: rustc_typeck::check::wfcheck::check_item_well_formed
  43: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::check_item_well_formed<'tcx>>::compute
  44: rustc::dep_graph::graph::DepGraph::with_task_impl
  45: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  46: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with
  48: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  49: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'v>>::visit_item
  50: rustc::hir::Crate::visit_all_item_likes
  51: rustc::util::common::time
  52: rustc_typeck::check_crate
  53: <std::thread::local::LocalKey<T>>::with
  54: rustc::ty::context::TyCtxt::create_and_enter
  55: rustc_driver::driver::compile_input
  56: rustc_driver::run_compiler_with_pool
  57: <scoped_tls::ScopedKey<T>>::set
  58: rustc_driver::run_compiler
  59: <scoped_tls::ScopedKey<T>>::set
  60: syntax::with_globals
  61: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:92
  62: <F as alloc::boxed::FnBox<A>>::call_box
  63: std::sys::unix::thread::Thread::new::thread_start
             at /rustc/b2b7a063af39455d7362524da3123c34c3f4842e/src/liballoc/boxed.rs:734
             at src/libstd/sys_common/thread.rs:14
             at src/libstd/sys/unix/thread.rs:81
  64: start_thread
  65: clone
query stack during panic:
#0 [adt_sized_constraint] processing `DieRollAction`
#1 [check_item_well_formed] processing `Action`
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.33.0-nightly (b2b7a063a 2019-01-01) 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 `nested-enums`.

To learn more, run the command again with --verbose.

Instead, I would have expected the following error message:

error[E0072]: recursive type `Outer` has infinite size

This is the code:

#[derive(Debug)]
pub enum Action {
    Unknown(Option<Vec<String>>),
    AreaSelection(usize, Box<Action>),
    CardGive(usize, usize, Option<Vec<usize>>),
    CardPlayed(usize),
    CardSell(Option<Vec<usize>>, usize, usize, Option<usize>, usize),
    CardTake(usize, Option<Vec<usize>>),
    // THE BUG EXISTS IN THIS ENUM-VARIANT (see definition below)
    DieRoll(DieRollAction),
    HouseBuild(usize, Option<usize>),
    HouseDestruct,
    HouseReplace(usize),
    IgnoreRandomEvent(usize),
    IncreaseCardBudget(usize),
    Interrupt,
    InterruptSelf,
    InvestigatePersonalities(Option<Vec<usize>>),
    Kill(usize, bool, usize, bool),
    Loan(usize, usize),
    LoanPayback(usize),
    MinionMove(usize, usize, usize),
    MinionPlace(usize, bool),
    MinionSwap((usize, usize), (usize, usize)),
    MoneyGive(usize),
    MoneyTake(usize, usize),
    None,
    PersonalityExchange(Option<usize>, Option<usize>),
    RandomEvent,
    SwapHand((usize, Option<Vec<usize>>), (usize, Option<Vec<usize>>)),
    Text(Vec<Action>),
    TroublePlace(usize),
    TroubleRemove(usize),
    TurnStart(usize, bool),
    TurnEnd(usize, Vec<usize>),
}

#[derive(Debug)]
pub enum DieRollAction {
    DieRollRequest(u64, usize),
    DieRollResult(u64, Vec<usize>),
    Specification(usize, usize),
    // Here we create a recursive data structure without indirection
    DieRollExec(u64, (usize, Action)),
}

fn main() {
    let oo = Action::TurnStart(0, true);
    println!("{:#?}", oo);
}

Important Note: For submitting this bug report, I tried to sanitize the data structure (less variants, simplified names, etc.), however doing any changes (even if just renaming Action to something like Outer) removed the bug and resulted in the "infinite size" error, as expected.

@jonas-schievink jonas-schievink 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. labels Jan 26, 2019
@jonas-schievink
Copy link
Contributor

I'm unable to reproduce this on Linux using this command line

env RUST_BACKTRACE=1 rustc +nightly-2019-01-02 -Cincremental=incr -Cdebuginfo=2 --crate-type bin test.rs

This might be caused by a previous incremental compilation.

@z2oh
Copy link

z2oh commented Jan 29, 2019

I just ran into this issue myself. I changed an enum to be recursive (a bug on my part) and the compiler panicked. After running cargo clean and rebuilding, I got the expected recursive without indirection error.

Looks like @jonas-schievink is correct in blaming previous incremental compilation.

Here is my full error output from before running cargo clean:

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

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:590:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
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.33.0-nightly (a7be40c65 2018-12-26) 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

error: Could not compile `project`.

To learn more, run the command again with --verbose.

@jonas-schievink jonas-schievink added the A-incr-comp Area: Incremental compilation label Jan 29, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Mar 29, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2019

triage: P-high.

@pnkfelix pnkfelix added the P-high High priority label Jun 6, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Jun 6, 2019

assigning to @nikomatsakis with expectation that they will delegate.

@pnkfelix
Copy link
Member

triage: reassigning to self (for either investigation or delegation).

@pnkfelix pnkfelix assigned pnkfelix and unassigned nikomatsakis Sep 19, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Oct 3, 2019

triage: downgrading to P-medium because having this in weekly triage does not make sense.

@pnkfelix pnkfelix added P-medium Medium priority and removed P-high High priority labels Oct 3, 2019
@Lythenas
Copy link

Lythenas commented Nov 8, 2019

I just ran into this ICE. As @z2oh pointed out after cargo clean the error is gone.

@gizmondo
Copy link
Contributor

gizmondo commented Dec 8, 2019

Can probably be closed as a duplicate of #61323?

@Mark-Simulacrum
Copy link
Member

Seems plausible. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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

8 participants