Skip to content

Commit 88b10c1

Browse files
author
Lukas Markeffsky
committed
include ParamEnv in projection cache key
1 parent 584f183 commit 88b10c1

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

compiler/rustc_infer/src/traits/project.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ pub struct ProjectionCacheStorage<'tcx> {
7878
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
7979
pub struct ProjectionCacheKey<'tcx> {
8080
ty: ty::AliasTy<'tcx>,
81+
param_env: ty::ParamEnv<'tcx>,
8182
}
8283

8384
impl<'tcx> ProjectionCacheKey<'tcx> {
84-
pub fn new(ty: ty::AliasTy<'tcx>) -> Self {
85-
Self { ty }
85+
pub fn new(ty: ty::AliasTy<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
86+
Self { ty, param_env }
8687
}
8788
}
8889

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -758,9 +758,9 @@ impl<'a, 'tcx> FulfillProcessor<'a, 'tcx> {
758758
// no type variables present, can use evaluation for better caching.
759759
// FIXME: consider caching errors too.
760760
if self.selcx.infcx.predicate_must_hold_considering_regions(obligation) {
761-
if let Some(key) = ProjectionCacheKey::from_poly_projection_predicate(
761+
if let Some(key) = ProjectionCacheKey::from_poly_projection_obligation(
762762
&mut self.selcx,
763-
project_obligation.predicate,
763+
&project_obligation,
764764
) {
765765
// If `predicate_must_hold_considering_regions` succeeds, then we've
766766
// evaluated all sub-obligations. We can therefore mark the 'root'

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ pub(super) fn opt_normalize_projection_type<'a, 'b, 'tcx>(
344344
let use_cache = !selcx.is_intercrate();
345345

346346
let projection_ty = infcx.resolve_vars_if_possible(projection_ty);
347-
let cache_key = ProjectionCacheKey::new(projection_ty);
347+
let cache_key = ProjectionCacheKey::new(projection_ty, param_env);
348348

349349
// FIXME(#20304) For now, I am caching here, which is good, but it
350350
// means we don't capture the type variables that are created in
@@ -2105,27 +2105,28 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
21052105
}
21062106

21072107
pub(crate) trait ProjectionCacheKeyExt<'cx, 'tcx>: Sized {
2108-
fn from_poly_projection_predicate(
2108+
fn from_poly_projection_obligation(
21092109
selcx: &mut SelectionContext<'cx, 'tcx>,
2110-
predicate: ty::PolyProjectionPredicate<'tcx>,
2110+
obligation: &PolyProjectionObligation<'tcx>,
21112111
) -> Option<Self>;
21122112
}
21132113

21142114
impl<'cx, 'tcx> ProjectionCacheKeyExt<'cx, 'tcx> for ProjectionCacheKey<'tcx> {
2115-
fn from_poly_projection_predicate(
2115+
fn from_poly_projection_obligation(
21162116
selcx: &mut SelectionContext<'cx, 'tcx>,
2117-
predicate: ty::PolyProjectionPredicate<'tcx>,
2117+
obligation: &PolyProjectionObligation<'tcx>,
21182118
) -> Option<Self> {
21192119
let infcx = selcx.infcx;
21202120
// We don't do cross-snapshot caching of obligations with escaping regions,
21212121
// so there's no cache key to use
2122-
predicate.no_bound_vars().map(|predicate| {
2122+
obligation.predicate.no_bound_vars().map(|predicate| {
21232123
ProjectionCacheKey::new(
21242124
// We don't attempt to match up with a specific type-variable state
21252125
// from a specific call to `opt_normalize_projection_type` - if
21262126
// there's no precise match, the original cache entry is "stranded"
21272127
// anyway.
21282128
infcx.resolve_vars_if_possible(predicate.projection_ty),
2129+
obligation.param_env,
21292130
)
21302131
})
21312132
}

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
815815
// `EvaluatedToOkModuloRegions`), and skip re-evaluating the
816816
// sub-obligations.
817817
if let Some(key) =
818-
ProjectionCacheKey::from_poly_projection_predicate(self, data)
818+
ProjectionCacheKey::from_poly_projection_obligation(
819+
self,
820+
&project_obligation,
821+
)
819822
{
820823
if let Some(cached_res) = self
821824
.infcx
@@ -844,8 +847,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
844847
&& (eval_rslt == EvaluatedToOk
845848
|| eval_rslt == EvaluatedToOkModuloRegions)
846849
&& let Some(key) =
847-
ProjectionCacheKey::from_poly_projection_predicate(
848-
self, data,
850+
ProjectionCacheKey::from_poly_projection_obligation(
851+
self,
852+
&project_obligation,
849853
)
850854
{
851855
// If the result is something that we can cache, then mark this

0 commit comments

Comments
 (0)