Rollup merge of #129725 - compiler-errors:predicates-of, r=fmease
Stop using `ty::GenericPredicates` for non-predicates_of queries
`GenericPredicates` is a struct of several parts: A list of of an item's own predicates, and a parent def id (and some effects related stuff, but ignore that since it's kinda irrelevant). When instantiating these generic predicates, it calls `predicates_of` on the parent and instantiates its predicates, and appends the item's own instantiated predicates too:
acb4e8b625/compiler/rustc_middle/src/ty/generics.rs (L407-L413)
Notice how this should result in a recursive set of calls to `predicates_of`... However, `GenericPredicates` is *also* misused by a bunch of *other* queries as a convenient way of passing around a list of predicates. For these queries, we don't ever set the parent def id of the `GenericPredicates`, but if we did, then this would be very easy to mistakenly call `predicates_of` instead of some other intended parent query.
Given that footgun, and the fact that we don't ever even *use* the parent def id in the `GenericPredicates` returned from queries like `explicit_super_predicates_of`, It really has no benefit over just returning `&'tcx [(Clause<'tcx>, Span)]`.
This PR additionally opts to wrap the results of `EarlyBinder`, as we've tended to use that in the return type of these kinds of queries to properly convey that the user has params to deal with, and it also gives a convenient way of iterating over a slice of things after instantiating.
This commit is contained in:
commit
5f10a99c7a
20 changed files with 101 additions and 98 deletions
|
@ -651,7 +651,7 @@ rustc_queries! {
|
|||
/// is a subset of the full list of predicates. We store these in a separate map
|
||||
/// because we must evaluate them even during type conversion, often before the full
|
||||
/// predicates are available (note that super-predicates must not be cyclic).
|
||||
query explicit_super_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
|
||||
query explicit_super_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
desc { |tcx| "computing the super predicates of `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { key.is_local() }
|
||||
separate_provide_extern
|
||||
|
@ -662,7 +662,7 @@ rustc_queries! {
|
|||
/// of the trait. For regular traits, this includes all super-predicates and their
|
||||
/// associated type bounds. For trait aliases, currently, this includes all of the
|
||||
/// predicates of the trait alias.
|
||||
query explicit_implied_predicates_of(key: DefId) -> ty::GenericPredicates<'tcx> {
|
||||
query explicit_implied_predicates_of(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
desc { |tcx| "computing the implied predicates of `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { key.is_local() }
|
||||
separate_provide_extern
|
||||
|
@ -671,7 +671,9 @@ rustc_queries! {
|
|||
/// The Ident is the name of an associated type.The query returns only the subset
|
||||
/// of supertraits that define the given associated type. This is used to avoid
|
||||
/// cycles in resolving type-dependent associated item paths like `T::Item`.
|
||||
query explicit_supertraits_containing_assoc_item(key: (DefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
|
||||
query explicit_supertraits_containing_assoc_item(
|
||||
key: (DefId, rustc_span::symbol::Ident)
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
desc { |tcx| "computing the super traits of `{}` with associated type name `{}`",
|
||||
tcx.def_path_str(key.0),
|
||||
key.1
|
||||
|
@ -680,7 +682,9 @@ rustc_queries! {
|
|||
|
||||
/// To avoid cycles within the predicates of a single item we compute
|
||||
/// per-type-parameter predicates for resolving `T::AssocTy`.
|
||||
query type_param_predicates(key: (LocalDefId, LocalDefId, rustc_span::symbol::Ident)) -> ty::GenericPredicates<'tcx> {
|
||||
query type_param_predicates(
|
||||
key: (LocalDefId, LocalDefId, rustc_span::symbol::Ident)
|
||||
) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
|
||||
desc { |tcx| "computing the bounds for type parameter `{}`", tcx.hir().ty_param_name(key.1) }
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue