Prefer TraitPredicate over ConstnessAnd<TraitRef>

This commit is contained in:
Oli Scherer 2021-10-21 18:12:19 +00:00 committed by Deadbeef
parent 40f39e6c6a
commit b16c811f1c
No known key found for this signature in database
GPG key ID: 6D017A96D8E6C2F9
2 changed files with 10 additions and 25 deletions

View file

@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId;
use rustc_query_system::cache::Cache; use rustc_query_system::cache::Cache;
pub type SelectionCache<'tcx> = Cache< pub type SelectionCache<'tcx> = Cache<
(ty::ConstnessAnd<ty::ParamEnvAnd<'tcx, ty::TraitRef<'tcx>>>, ty::ImplPolarity), ty::ParamEnvAnd<'tcx, ty::TraitPredicate<'tcx>>,
SelectionResult<'tcx, SelectionCandidate<'tcx>>, SelectionResult<'tcx, SelectionCandidate<'tcx>>,
>; >;

View file

@ -1231,19 +1231,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
return None; return None;
} }
let tcx = self.tcx(); let tcx = self.tcx();
let pred = &cache_fresh_trait_pred.skip_binder(); let pred = cache_fresh_trait_pred.skip_binder();
let trait_ref = pred.trait_ref;
if self.can_use_global_caches(param_env) { if self.can_use_global_caches(param_env) {
if let Some(res) = tcx if let Some(res) = tcx.selection_cache.get(&param_env.and(pred), tcx) {
.selection_cache
.get(&(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity), tcx)
{
return Some(res); return Some(res);
} }
} }
self.infcx self.infcx.selection_cache.get(&param_env.and(pred), tcx)
.selection_cache
.get(&(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity), tcx)
} }
/// Determines whether can we safely cache the result /// Determines whether can we safely cache the result
@ -1288,36 +1282,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) { ) {
let tcx = self.tcx(); let tcx = self.tcx();
let pred = cache_fresh_trait_pred.skip_binder(); let pred = cache_fresh_trait_pred.skip_binder();
let trait_ref = pred.trait_ref;
if !self.can_cache_candidate(&candidate) { if !self.can_cache_candidate(&candidate) {
debug!(?trait_ref, ?candidate, "insert_candidate_cache - candidate is not cacheable"); debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
return; return;
} }
if self.can_use_global_caches(param_env) { if self.can_use_global_caches(param_env) {
if let Err(Overflow) = candidate { if let Err(Overflow) = candidate {
// Don't cache overflow globally; we only produce this in certain modes. // Don't cache overflow globally; we only produce this in certain modes.
} else if !trait_ref.needs_infer() { } else if !pred.needs_infer() {
if !candidate.needs_infer() { if !candidate.needs_infer() {
debug!(?trait_ref, ?candidate, "insert_candidate_cache global"); debug!(?pred, ?candidate, "insert_candidate_cache global");
// This may overwrite the cache with the same value. // This may overwrite the cache with the same value.
tcx.selection_cache.insert( tcx.selection_cache.insert(param_env.and(pred), dep_node, candidate);
(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity),
dep_node,
candidate,
);
return; return;
} }
} }
} }
debug!(?trait_ref, ?candidate, "insert_candidate_cache local"); debug!(?pred, ?candidate, "insert_candidate_cache local");
self.infcx.selection_cache.insert( self.infcx.selection_cache.insert(param_env.and(pred), dep_node, candidate);
(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity),
dep_node,
candidate,
);
} }
/// Matches a predicate against the bounds of its self type. /// Matches a predicate against the bounds of its self type.