Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e0c38af

Browse files
committedSep 17, 2021
Auto merge of #88945 - Aaron1011:no-projection-completion, r=wesleywiser,jackh726
Remove concept of 'completion' from the projection cache Fixes #88910 When we initially store a `NormalizedTy` in the projection cache, we discard all obligations that we can (while ensuring that we don't cause any issues with incremental compilation). Marking a projection cache entry as 'completed' discards all obligations associated with it. This can only cause problems, since any obligations stored in the cache are there for a reason (e.g. they evaluate to `EvaluatedToOkModuloRegions`). This commit removes `complete` and `complete_normalized` entirely.
2 parents 1c03f0d + 055651d commit e0c38af

File tree

2 files changed

+2
-51
lines changed
  • compiler

2 files changed

+2
-51
lines changed
 

‎compiler/rustc_infer/src/traits/project.rs

-41
Original file line numberDiff line numberDiff line change
@@ -153,47 +153,6 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
153153
assert!(!fresh_key, "never started projecting `{:?}`", key);
154154
}
155155

156-
/// Mark the relevant projection cache key as having its derived obligations
157-
/// complete, so they won't have to be re-computed (this is OK to do in a
158-
/// snapshot - if the snapshot is rolled back, the obligations will be
159-
/// marked as incomplete again).
160-
pub fn complete(&mut self, key: ProjectionCacheKey<'tcx>) {
161-
let mut map = self.map();
162-
let ty = match map.get(&key) {
163-
Some(&ProjectionCacheEntry::NormalizedTy(ref ty)) => {
164-
debug!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
165-
ty.value
166-
}
167-
ref value => {
168-
// Type inference could "strand behind" old cache entries. Leave
169-
// them alone for now.
170-
debug!("ProjectionCacheEntry::complete({:?}) - ignoring {:?}", key, value);
171-
return;
172-
}
173-
};
174-
175-
map.insert(
176-
key,
177-
ProjectionCacheEntry::NormalizedTy(Normalized { value: ty, obligations: vec![] }),
178-
);
179-
}
180-
181-
/// A specialized version of `complete` for when the key's value is known
182-
/// to be a NormalizedTy.
183-
pub fn complete_normalized(&mut self, key: ProjectionCacheKey<'tcx>, ty: &NormalizedTy<'tcx>) {
184-
// We want to insert `ty` with no obligations. If the existing value
185-
// already has no obligations (as is common) we don't insert anything.
186-
if !ty.obligations.is_empty() {
187-
self.map().insert(
188-
key,
189-
ProjectionCacheEntry::NormalizedTy(Normalized {
190-
value: ty.value,
191-
obligations: vec![],
192-
}),
193-
);
194-
}
195-
}
196-
197156
/// Indicates that trying to normalize `key` resulted in
198157
/// ambiguity. No point in trying it again then until we gain more
199158
/// type information (in which case, the "fully resolved" key will

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,17 @@ use super::util;
1414
use super::util::{closure_trait_ref_and_return_type, predicate_for_trait_def};
1515
use super::wf;
1616
use super::DerivedObligationCause;
17+
use super::Normalized;
1718
use super::Obligation;
1819
use super::ObligationCauseCode;
1920
use super::Selection;
2021
use super::SelectionResult;
2122
use super::TraitQueryMode;
22-
use super::{Normalized, ProjectionCacheKey};
2323
use super::{ObligationCause, PredicateObligation, TraitObligation};
2424
use super::{Overflow, SelectionError, Unimplemented};
2525

2626
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
2727
use crate::traits::error_reporting::InferCtxtExt;
28-
use crate::traits::project::ProjectionCacheKeyExt;
2928
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3029
use rustc_data_structures::stack::ensure_sufficient_stack;
3130
use rustc_data_structures::sync::Lrc;
@@ -574,14 +573,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
574573
match project::poly_project_and_unify_type(self, &project_obligation) {
575574
Ok(Ok(Some(mut subobligations))) => {
576575
self.add_depth(subobligations.iter_mut(), obligation.recursion_depth);
577-
let result = self
578-
.evaluate_predicates_recursively(previous_stack, subobligations);
579-
if let Some(key) =
580-
ProjectionCacheKey::from_poly_projection_predicate(self, data)
581-
{
582-
self.infcx.inner.borrow_mut().projection_cache().complete(key);
583-
}
584-
result
576+
self.evaluate_predicates_recursively(previous_stack, subobligations)
585577
}
586578
Ok(Ok(None)) => Ok(EvaluatedToAmbig),
587579
Ok(Err(project::InProgress)) => Ok(EvaluatedToRecur),

0 commit comments

Comments
 (0)