Skip to content

Commit cde1f6a

Browse files
committed
Prefer TraitPredicate over ConstnessAnd<TraitRef>
1 parent 104593f commit cde1f6a

File tree

2 files changed

+10
-25
lines changed
  • compiler
    • rustc_middle/src/traits
    • rustc_trait_selection/src/traits/select

2 files changed

+10
-25
lines changed

compiler/rustc_middle/src/traits/select.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::def_id::DefId;
1212
use rustc_query_system::cache::Cache;
1313

1414
pub type SelectionCache<'tcx> = Cache<
15-
(ty::ConstnessAnd<ty::ParamEnvAnd<'tcx, ty::TraitRef<'tcx>>>, ty::ImplPolarity),
15+
ty::ParamEnvAnd<'tcx, ty::TraitPredicate<'tcx>>,
1616
SelectionResult<'tcx, SelectionCandidate<'tcx>>,
1717
>;
1818

compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,19 +1231,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12311231
return None;
12321232
}
12331233
let tcx = self.tcx();
1234-
let pred = &cache_fresh_trait_pred.skip_binder();
1235-
let trait_ref = pred.trait_ref;
1234+
let pred = cache_fresh_trait_pred.skip_binder();
12361235
if self.can_use_global_caches(param_env) {
1237-
if let Some(res) = tcx
1238-
.selection_cache
1239-
.get(&(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity), tcx)
1240-
{
1236+
if let Some(res) = tcx.selection_cache.get(&param_env.and(pred), tcx) {
12411237
return Some(res);
12421238
}
12431239
}
1244-
self.infcx
1245-
.selection_cache
1246-
.get(&(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity), tcx)
1240+
self.infcx.selection_cache.get(&param_env.and(pred), tcx)
12471241
}
12481242

12491243
/// Determines whether can we safely cache the result
@@ -1288,36 +1282,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
12881282
) {
12891283
let tcx = self.tcx();
12901284
let pred = cache_fresh_trait_pred.skip_binder();
1291-
let trait_ref = pred.trait_ref;
12921285

12931286
if !self.can_cache_candidate(&candidate) {
1294-
debug!(?trait_ref, ?candidate, "insert_candidate_cache - candidate is not cacheable");
1287+
debug!(?pred, ?candidate, "insert_candidate_cache - candidate is not cacheable");
12951288
return;
12961289
}
12971290

12981291
if self.can_use_global_caches(param_env) {
12991292
if let Err(Overflow) = candidate {
13001293
// Don't cache overflow globally; we only produce this in certain modes.
1301-
} else if !trait_ref.needs_infer() {
1294+
} else if !pred.needs_infer() {
13021295
if !candidate.needs_infer() {
1303-
debug!(?trait_ref, ?candidate, "insert_candidate_cache global");
1296+
debug!(?pred, ?candidate, "insert_candidate_cache global");
13041297
// This may overwrite the cache with the same value.
1305-
tcx.selection_cache.insert(
1306-
(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity),
1307-
dep_node,
1308-
candidate,
1309-
);
1298+
tcx.selection_cache.insert(param_env.and(pred), dep_node, candidate);
13101299
return;
13111300
}
13121301
}
13131302
}
13141303

1315-
debug!(?trait_ref, ?candidate, "insert_candidate_cache local");
1316-
self.infcx.selection_cache.insert(
1317-
(param_env.and(trait_ref).with_constness(pred.constness), pred.polarity),
1318-
dep_node,
1319-
candidate,
1320-
);
1304+
debug!(?pred, ?candidate, "insert_candidate_cache local");
1305+
self.infcx.selection_cache.insert(param_env.and(pred), dep_node, candidate);
13211306
}
13221307

13231308
/// Matches a predicate against the bounds of its self type.

0 commit comments

Comments
 (0)