1
Fork 0

Auto merge of #128776 - Bryanskiy:deep-reject-ctxt, r=lcnr

Use `DeepRejectCtxt` to quickly reject `ParamEnv` candidates

The description is on the [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/.5Basking.20for.20help.5D.20.60DeepRejectCtxt.60.20for.20param.20env.20candidates)

r? `@lcnr`
This commit is contained in:
bors 2024-09-06 19:50:48 +00:00
commit 26b5599e4d
16 changed files with 287 additions and 167 deletions

View file

@ -426,7 +426,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
let simp = ty::fast_reject::simplify_type(
tcx,
self_ty,
ty::fast_reject::TreatParams::ForLookup,
ty::fast_reject::TreatParams::AsRigid,
)
.unwrap();
consider_impls_for_simplified_type(simp);

View file

@ -3,6 +3,14 @@ pub use rustc_type_ir::fast_reject::*;
use super::TyCtxt;
pub type DeepRejectCtxt<'tcx> = rustc_type_ir::fast_reject::DeepRejectCtxt<TyCtxt<'tcx>>;
pub type DeepRejectCtxt<
'tcx,
const INSTANTIATE_LHS_WITH_INFER: bool,
const INSTANTIATE_RHS_WITH_INFER: bool,
> = rustc_type_ir::fast_reject::DeepRejectCtxt<
TyCtxt<'tcx>,
INSTANTIATE_LHS_WITH_INFER,
INSTANTIATE_RHS_WITH_INFER,
>;
pub type SimplifiedType = rustc_type_ir::fast_reject::SimplifiedType<DefId>;

View file

@ -168,9 +168,9 @@ impl<'tcx> TyCtxt<'tcx> {
// whose outer level is not a parameter or projection. Especially for things like
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
// `TreatParams::AsCandidateKey` while actually adding them.
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::ForLookup) {
// Note that we're using `TreatParams::AsRigid` to query `non_blanket_impls` while using
// `TreatParams::InstantiateWithInfer` while actually adding them.
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsRigid) {
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
for &impl_def_id in impls {
f(impl_def_id);
@ -190,7 +190,9 @@ impl<'tcx> TyCtxt<'tcx> {
self_ty: Ty<'tcx>,
) -> impl Iterator<Item = DefId> + 'tcx {
let impls = self.trait_impls_of(trait_def_id);
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::AsCandidateKey) {
if let Some(simp) =
fast_reject::simplify_type(self, self_ty, TreatParams::InstantiateWithInfer)
{
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
return impls.iter().copied();
}
@ -239,7 +241,7 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if let Some(simplified_self_ty) =
fast_reject::simplify_type(tcx, impl_self_ty, TreatParams::AsCandidateKey)
fast_reject::simplify_type(tcx, impl_self_ty, TreatParams::InstantiateWithInfer)
{
impls.non_blanket_impls.entry(simplified_self_ty).or_default().push(impl_def_id);
} else {