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 #84727

Closed
truchi opened this issue Apr 29, 2021 · 4 comments · Fixed by #123051
Closed

ICE #84727

truchi opened this issue Apr 29, 2021 · 4 comments · Fixed by #123051
Labels
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) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@truchi
Copy link

truchi commented Apr 29, 2021

Code

pub struct Color<T>(pub T);

pub struct Cell<Fg, Bg = Fg> {
    foreground: Color<Fg>,
    background: Color<Bg>,
}

pub trait Over<Bottom, Output> {
    fn over(self, bottom: Bottom) -> Output;
}

// Cell: Over<Color, Cell>
impl<C, Fg, Bg, NewFg, NewBg> Over<Color<C>, Cell<NewFg, NewBg>> for Cell<Fg, Bg>
where
    Fg: Over<C, NewFg>,
    Bg: Over<C, NewBg>,
{
    fn over(self, _: Color<C>) -> Cell<NewFg, NewBg> {
        todo!();
    }
}

// Cell: Over<Cell, Cell>
impl<TopFg, TopBg, BottomFg, BottomBg, NewFg, NewBg>
    Over<Cell<BottomFg, BottomBg>, Cell<NewFg, NewBg>> for Cell<TopFg, TopBg>
where
    Self: Over<Color<BottomBg>, Cell<NewFg, NewBg>>,
{
    fn over(self, bottom: Cell<BottomFg, BottomBg>) -> Cell<NewFg, NewBg> {
        self.over(bottom.background);
        todo!();
    }
}

// Cell: Over<&mut Cell, ()>
impl<'b, TopFg, TopBg, BottomFg, BottomBg> Over<&'b mut Cell<BottomFg, BottomBg>, ()>
    for Cell<TopFg, TopBg>
where
    Cell<TopFg, TopBg>: Over<Cell<BottomFg, BottomBg>, Cell<BottomFg, BottomBg>>,
{
    fn over(self, _: &'b mut Cell<BottomFg, BottomBg>) {
        todo!();
    }
}

// &Cell: Over<&mut Cell, ()>
impl<'t, 'b, TopFg, TopBg, BottomFg, BottomBg> Over<&'b mut Cell<BottomFg, BottomBg>, ()>
    for &'t Cell<TopFg, TopBg>
where
    Cell<TopFg, TopBg>: Over<Cell<BottomFg, BottomBg>, Cell<BottomFg, BottomBg>>,
{
    fn over(self, _: &'b mut Cell<BottomFg, BottomBg>) {
        todo!();
    }
}

Meta

rustc --version --verbose:

rustc 1.53.0-nightly (42816d61e 2021-04-24)
binary: rustc
commit-hash: 42816d61ead7e46d462df997958ccfd514f8c21c
commit-date: 2021-04-24
host: x86_64-unknown-linux-gnu
release: 1.53.0-nightly
LLVM version: 12.0.0

Same in 1.52.0-nightly, same in 1.51.0.

Error output

error: internal compiler error: compiler/rustc_trait_selection/src/traits/select/confirmation.rs:201:17: Where clause `Binder(<style::color::Color<TopBg> as style::Over<style::cell::Cell<BottomFg, BottomBg>, style::cell::Cell<NewFg, NewBg>>>, [])` was applicable to `Obligation(predicate=Binder(TraitPredicate(<style::color::Color<TopBg> as style::Over<style::cell::Cell<_, _>, style::cell::Cell<_, _>>>), []), depth=2)` but now is not

thread 'rustc' panicked at 'Box<Any>', /rustc/42816d61ead7e46d462df997958ccfd514f8c21c/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.53.0-nightly (42816d61e 2021-04-24) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `style::cell::Cell<TopFg, TopBg>: style::Over<^1_0, ^1_1>`
#1 [typeck] type-checking `style::cell::<impl at src/style/cell.rs:74:1: 91:2>::over`
end of query stack
error: aborting due to previous error

error: could not compile `tender`

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

RUST_BACKTRACE=1 cargo build:

Backtrace

error: internal compiler error: compiler/rustc_trait_selection/src/traits/select/confirmation.rs:201:17: Where clause `Binder(<style::color::Color<TopBg> as style::Over<style::cell::Cell<BottomFg, BottomBg>, style::cell::Cell<NewFg, NewBg>>>, [])` was applicable to `Obligation(predicate=Binder(TraitPredicate(<style::color::Color<TopBg> as style::Over<style::cell::Cell<_, _>, style::cell::Cell<_, _>>>), []), depth=2)` but now is not

thread 'rustc' panicked at 'Box<Any>', /rustc/42816d61ead7e46d462df997958ccfd514f8c21c/library/std/src/panic.rs:59:5
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util::bug::opt_span_bug_fmt
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_trait_selection::traits::select::confirmation::<impl rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   8: rustc_infer::infer::InferCtxt::probe
   9: rustc_trait_selection::traits::select::SelectionContext::evaluate_candidate
  10: rustc_trait_selection::traits::select::SelectionContext::evaluate_stack
  11: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  12: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  13: rustc_trait_selection::traits::select::SelectionContext::evaluate_trait_predicate_recursively
  14: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively::{{closure}}
  15: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively
  16: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicates_recursively
  17: rustc_infer::infer::InferCtxt::probe
  18: rustc_trait_selection::traits::select::SelectionContext::evaluate_candidate
  19: rustc_trait_selection::traits::select::SelectionContext::evaluate_stack
  20: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  21: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  22: rustc_trait_selection::traits::select::SelectionContext::evaluate_trait_predicate_recursively
  23: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively::{{closure}}
  24: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively
  25: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicates_recursively
  26: rustc_infer::infer::InferCtxt::probe
  27: rustc_trait_selection::traits::select::SelectionContext::evaluate_candidate
  28: <core::iter::adapters::ResultShunt<I,E> as core::iter::traits::iterator::Iterator>::next
  29: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  30: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation_no_cache
  31: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  32: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  33: rustc_trait_selection::traits::select::candidate_assembly::<impl rustc_trait_selection::traits::select::SelectionContext>::candidate_from_obligation
  34: rustc_trait_selection::traits::select::SelectionContext::evaluate_stack
  35: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  36: rustc_query_system::dep_graph::graph::DepGraph<K>::with_anon_task
  37: rustc_trait_selection::traits::select::SelectionContext::evaluate_trait_predicate_recursively
  38: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively::{{closure}}
  39: rustc_trait_selection::traits::select::SelectionContext::evaluate_predicate_recursively
  40: rustc_infer::infer::InferCtxt::probe
  41: rustc_trait_selection::traits::select::SelectionContext::evaluate_root_obligation
  42: rustc_infer::infer::InferCtxtBuilder::enter_with_canonical
  43: rustc_traits::evaluate_obligation::evaluate_obligation
  44: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::evaluate_obligation>::compute
  45: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  46: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  47: rustc_data_structures::stack::ensure_sufficient_stack
  48: rustc_query_system::query::plumbing::force_query_with_job
  49: rustc_query_system::query::plumbing::get_query_impl
  50: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
  51: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation
  52: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::evaluate_obligation_no_overflow
  53: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_may_hold
  54: rustc_infer::infer::InferCtxt::probe
  55: <alloc::vec::Vec<T> as alloc::vec::spec_from_iter::SpecFromIter<T,I>>::from_iter
  56: rustc_typeck::check::method::probe::ProbeContext::pick_method
  57: rustc_typeck::check::method::probe::ProbeContext::pick_core
  58: rustc_typeck::check::method::probe::ProbeContext::pick
  59: rustc_infer::infer::InferCtxt::probe
  60: rustc_typeck::check::method::probe::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::probe_for_name
  61: rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_probe
  62: rustc_typeck::check::method::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method
  63: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  64: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  65: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  66: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  67: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  68: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  69: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  70: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  71: rustc_typeck::check::fn_ctxt::checks::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  72: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation
  73: rustc_typeck::check::expr::<impl rustc_typeck::check::fn_ctxt::FnCtxt>::check_return_expr
  74: rustc_typeck::check::check::check_fn
  75: rustc_infer::infer::InferCtxtBuilder::enter
  76: rustc_typeck::check::typeck
  77: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  78: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  79: rustc_data_structures::stack::ensure_sufficient_stack
  80: rustc_query_system::query::plumbing::force_query_with_job
  81: rustc_query_system::query::plumbing::get_query_impl
  82: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  83: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::par_body_owners
  84: rustc_typeck::check::typeck_item_bodies
  85: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  86: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  87: rustc_data_structures::stack::ensure_sufficient_stack
  88: rustc_query_system::query::plumbing::force_query_with_job
  89: rustc_query_system::query::plumbing::get_query_impl
  90: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck_item_bodies
  91: rustc_session::utils::<impl rustc_session::session::Session>::time
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0-nightly (42816d61e 2021-04-24) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [evaluate_obligation] evaluating trait selection obligation `style::cell::Cell<TopFg, TopBg>: style::Over<^1_0, ^1_1>`
#1 [typeck] type-checking `style::cell::<impl at src/style/cell.rs:74:1: 91:2>::over`
#2 [typeck_item_bodies] type-checking all item bodies
#3 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

error: could not compile `tender`

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

Good luck!
<3

@truchi truchi 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 Apr 29, 2021
@JohnTitor JohnTitor added the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Apr 30, 2021
@truchi
Copy link
Author

truchi commented Apr 30, 2021

This happens on top of too much code for me to take the time to minimalize this issue, sorry.
Though I'll try to file the fixing patch.

@truchi
Copy link
Author

truchi commented Apr 30, 2021

Wait! I made it! @JohnTitor

playground

pub struct Color<T>(pub T);

pub struct Cell<Fg, Bg = Fg> {
    foreground: Color<Fg>,
    background: Color<Bg>,
}

pub trait Over<Bottom, Output> {
    fn over(self, bottom: Bottom) -> Output;
}

// Cell: Over<Color, Cell>
impl<C, Fg, Bg, NewFg, NewBg> Over<Color<C>, Cell<NewFg, NewBg>> for Cell<Fg, Bg>
where
    Fg: Over<C, NewFg>,
    Bg: Over<C, NewBg>,
{
    fn over(self, _: Color<C>) -> Cell<NewFg, NewBg> {
        todo!();
    }
}

// Cell: Over<Cell, Cell>
impl<TopFg, TopBg, BottomFg, BottomBg, NewFg, NewBg>
    Over<Cell<BottomFg, BottomBg>, Cell<NewFg, NewBg>> for Cell<TopFg, TopBg>
where
    Self: Over<Color<BottomBg>, Cell<NewFg, NewBg>>,
{
    fn over(self, bottom: Cell<BottomFg, BottomBg>) -> Cell<NewFg, NewBg> {
        self.over(bottom.background);
        todo!();
    }
}

// Cell: Over<&mut Cell, ()>
impl<'b, TopFg, TopBg, BottomFg, BottomBg> Over<&'b mut Cell<BottomFg, BottomBg>, ()>
    for Cell<TopFg, TopBg>
where
    Cell<TopFg, TopBg>: Over<Cell<BottomFg, BottomBg>, Cell<BottomFg, BottomBg>>,
{
    fn over(self, _: &'b mut Cell<BottomFg, BottomBg>) {
        todo!();
    }
}

// &Cell: Over<&mut Cell, ()>
impl<'t, 'b, TopFg, TopBg, BottomFg, BottomBg> Over<&'b mut Cell<BottomFg, BottomBg>, ()>
    for &'t Cell<TopFg, TopBg>
where
    Cell<TopFg, TopBg>: Over<Cell<BottomFg, BottomBg>, Cell<BottomFg, BottomBg>>,
{
    fn over(self, _: &'b mut Cell<BottomFg, BottomBg>) {
        todo!();
    }
}

This issue revolves around L.31. Comment to see the ice go away.
Interestingly, comment L.40 (or the whole impl L.37-45) to see ice go away as well.
Commenting L.47-56 does not make ice go away.
Commenting L.13-22 should raise another error (as L.31 is supposed to go there), but doesn't.

Actually, the real fix is to replace L.31 with:

<_ as Over<_, Cell<NewFg, NewBg>>>::over(self, bottom.background)

playground

Have fun!
💖

@JohnTitor JohnTitor added A-trait-system Area: Trait system and removed E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Apr 30, 2021
fanninpm added a commit to fanninpm/glacier that referenced this issue Apr 30, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 30, 2021
@langston-barrett
Copy link

langston-barrett commented Mar 18, 2023

Minimized with Icemelter, then a bit by hand:

struct Cell<Fg, Bg = Fg> {
    foreground: Color<Fg>,
    background: Color<Bg>,
}

trait Over<Bottom, Output> {
    fn over(self) -> Output;
}

impl<TopFg, TopBg, BottomFg, BottomBg, NewFg, NewBg>
    Over<Cell<BottomFg, BottomBg>, Cell<NewFg, NewBg>> for Cell<TopFg, TopBg>
where
    Self: Over<Color<BottomBg>, Cell<NewFg>>,
{
    fn over(self) -> Cell<NewFg> {
        self.over();
    }
}

impl<'b, TopFg, TopBg, BottomFg, BottomBg> Over<&Cell<BottomFg, BottomBg>, ()>
    for Cell<TopFg, TopBg>
where
    Cell<TopFg, TopBg>: Over<Cell<BottomFg>, Cell<BottomFg>>,
{
    fn over(self) -> Cell<NewBg> {
        self.over();
    }
}
Details

Icemelter version: v0.2.0

@rustbot label +S-bug-has-mcve

@rustbot rustbot added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Mar 18, 2023
@matthiaskrgr matthiaskrgr added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Feb 23, 2024
@lcnr
Copy link
Contributor

lcnr commented Feb 23, 2024

fixed by #119989. we previously used sub_relations to eagerly error but did not consider them as part of the cache key. So using a cache key from an evaluation with different sub_relations can result in buggy behavior

workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 25, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this issue Mar 25, 2024
@bors bors closed this as completed in 6fe5555 Mar 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 26, 2024
Rollup merge of rust-lang#123051 - matthiaskrgr:casetest, r=workingjubilee

did I mention that tests are super cool?

Fixes rust-lang#81974
Fixes rust-lang#84727
Fixes rust-lang#92979
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Mar 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

7 participants