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

Regression in Deref<Target = dyn Fn(T)>: forcing query with already existing DepNode #91807

Closed
dtolnay opened this issue Dec 11, 2021 · 7 comments · Fixed by #91892
Closed

Regression in Deref<Target = dyn Fn(T)>: forcing query with already existing DepNode #91807

dtolnay opened this issue Dec 11, 2021 · 7 comments · Fixed by #91892
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-high High 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

@dtolnay
Copy link
Member

dtolnay commented Dec 11, 2021

The following code works in 1.56.0 but crashes 1.57.0 as well as the most recent nightly — rustc 1.59.0-nightly (0b42deacc 2021-12-09).

struct Struct<T>(T);

impl<T> std::ops::Deref for Struct<T> {
    type Target = dyn Fn(T);
    fn deref(&self) -> &Self::Target {
        unimplemented!()
    }
}

fn main() {
    let f = Struct(Default::default());
    f(0);
    f(0);
}
$ cargo check
thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Binder(std::ops::FnOnce<({integer},)>, [])
- dep-node: own_existential_vtable_entries(5494fdf0afa3bf46-73ce537069178b52)', /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/compiler/rustc_query_system/src/dep_graph/graph.rs:236:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

error: internal compiler error: unexpected panic

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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [own_existential_vtable_entries] finding all existential vtable entries for trait core::ops::function::FnOnce
#1 [evaluate_obligation] evaluating trait selection obligation `(dyn core::ops::function::Fn(^2_0) + 'static): core::ops::function::Fn<(^1_1,)>`
end of query stack
Backtrace

thread 'rustc' panicked at 'forcing query with already existing `DepNode`
- query-key: Binder(std::ops::FnOnce<({integer},)>, [])
- dep-node: own_existential_vtable_entries(5494fdf0afa3bf46-73ce537069178b52)', /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/compiler/rustc_query_system/src/dep_graph/graph.rs:236:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/0b42deaccc2cbe17a68067aa5fdb76104369e1fd/library/core/src/panicking.rs:107:14
   2: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>, &[rustc_span::def_id::DefId]>
   3: rustc_data_structures::stack::ensure_sufficient_stack::<(&[rustc_span::def_id::DefId], rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::ty::sty::Binder<rustc_middle::ty::sty::ExistentialTraitRef>, &[rustc_span::def_id::DefId]>::{closure#3}>
   4: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::own_existential_vtable_entries, rustc_query_impl::plumbing::QueryCtxt>
   5: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::own_existential_vtable_entries
   6: rustc_trait_selection::traits::util::count_own_vtable_entries
   7: rustc_trait_selection::traits::vtable_trait_first_method_offset
   8: <rustc_trait_selection::traits::select::SelectionContext>::confirm_candidate
   9: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_stack
  10: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
  11: <rustc_trait_selection::traits::select::SelectionContext>::evaluate_root_obligation
  12: <rustc_infer::infer::InferCtxtBuilder>::enter_with_canonical::<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_traits::evaluate_obligation::evaluate_obligation::{closure#0}>
  13: rustc_traits::evaluate_obligation::evaluate_obligation
  14: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>
  15: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_middle::infer::canonical::Canonical<rustc_middle::ty::ParamEnvAnd<rustc_middle::ty::Predicate>>, core::result::Result<rustc_middle::traits::select::EvaluationResult, rustc_middle::traits::select::OverflowError>>::{closure#3}>
  16: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::evaluate_obligation, rustc_query_impl::plumbing::QueryCtxt>
  17: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::evaluate_obligation
  18: <rustc_infer::infer::InferCtxt as rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt>::predicate_may_hold
  19: <rustc_typeck::check::fn_ctxt::FnCtxt>::lookup_method_in_trait
  20: <rustc_typeck::check::fn_ctxt::FnCtxt>::try_overloaded_call_traits
  21: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_call
  22: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_kind
  23: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  24: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_stmt
  25: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_block_with_expected
  26: <rustc_typeck::check::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  27: rustc_typeck::check::check::check_fn
  28: <rustc_infer::infer::InferCtxtBuilder>::enter::<&rustc_middle::ty::context::TypeckResults, <rustc_typeck::check::inherited::InheritedBuilder>::enter<rustc_typeck::check::typeck_with_fallback<rustc_typeck::check::typeck::{closure#0}>::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
  29: rustc_typeck::check::typeck
  30: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>
  31: rustc_data_structures::stack::ensure_sufficient_stack::<(&rustc_middle::ty::context::TypeckResults, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>::{closure#3}>
  32: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::LocalDefId, &rustc_middle::ty::context::TypeckResults>>
  33: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::typeck
  34: <rustc_middle::hir::map::Map>::par_body_owners::<rustc_typeck::check::typeck_item_bodies::{closure#0}>
  35: rustc_typeck::check::typeck_item_bodies
  36: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), ()>
  37: rustc_data_structures::stack::ensure_sufficient_stack::<((), rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), ()>::{closure#3}>
  38: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), ()>>
  39: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::typeck_item_bodies, rustc_query_impl::plumbing::QueryCtxt>
  40: <rustc_session::session::Session>::time::<(), rustc_typeck::check_crate::{closure#7}>
  41: rustc_typeck::check_crate
  42: rustc_interface::passes::analysis
  43: <rustc_query_system::dep_graph::graph::DepGraph<rustc_middle::dep_graph::dep_node::DepKind>>::with_task::<rustc_middle::ty::context::TyCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>
  44: rustc_data_structures::stack::ensure_sufficient_stack::<(core::result::Result<(), rustc_errors::ErrorReported>, rustc_query_system::dep_graph::graph::DepNodeIndex), rustc_query_system::query::plumbing::execute_job<rustc_query_impl::plumbing::QueryCtxt, (), core::result::Result<(), rustc_errors::ErrorReported>>::{closure#3}>
  45: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), core::result::Result<(), rustc_errors::ErrorReported>>>
  46: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::analysis, rustc_query_impl::plumbing::QueryCtxt>
  47: <rustc_interface::passes::QueryContext>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}::{closure#3}, core::result::Result<(), rustc_errors::ErrorReported>>
  48: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
  49: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  50: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

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.59.0-nightly (0b42deacc 2021-12-09) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [own_existential_vtable_entries] finding all existential vtable entries for trait core::ops::function::FnOnce
#1 [evaluate_obligation] evaluating trait selection obligation `(dyn core::ops::function::Fn(^2_0) + 'static): core::ops::function::Fn<(^1_1,)>`
#2 [typeck] type-checking `main`
#3 [typeck_item_bodies] type-checking all item bodies
#4 [analysis] running analysis passes on this crate
end of query stack

@dtolnay dtolnay 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. C-bug Category: This is a bug. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Dec 11, 2021
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 11, 2021
@dtolnay
Copy link
Member Author

dtolnay commented Dec 11, 2021

According to cargo-bisect-rustc the regression is from #88552 — FYI @nbdd0121 @nagisa


regressed nightly: nightly-2021-09-06
searched commit range: 5d2a410...e30b683
regressed commit: e30b683

bisected with cargo-bisect-rustc v0.6.1

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

cargo bisect-rustc 2021-08-28 --end 2021-09-09 --regress ice -- check 

@camelid camelid changed the title Regression in Deref<Target = dyn Fn(T)>: forcing query with already existing DepNode Regression in Deref<Target = dyn Fn(T)>: forcing query with already existing DepNode Dec 11, 2021
@nbdd0121
Copy link
Contributor

Seems that this is duplicate of #88929 and #91618; only triggers with incremental compilation enabled.

Unfortunately although I authored the original PR, I don't know a lot about incr-comp or the query system to diagnostic the issue.

@rustbot label: +A-incr-comp

@compiler-errors
Copy link
Member

Found the bug, I'll put up a PR in a sec.

@rustbot claim

@bors bors closed this as completed in d0e6bb7 Dec 14, 2021
@rustbot rustbot removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Dec 14, 2021
@pnkfelix
Copy link
Member

reopening as this is a stable-to-stable regression, and (I think) we keep those open until a fix lands on stable or we explicitly decline to fix.

@pnkfelix pnkfelix reopened this Dec 16, 2021
@pnkfelix pnkfelix added the P-high High priority label Dec 16, 2021
@matthiaskrgr
Copy link
Member

@pnkfelix was this backported / can we close the issue? :)

@teohhanhui
Copy link

The fix was backported and released in 1.58.0

#92592

@matthiaskrgr
Copy link
Member

Perfect, thanks for checking @teohhanhui !

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-high High 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.

7 participants