Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use super::{
};
use crate::error_reporting::InferCtxtErrorExt;
use crate::infer::{InferCtxt, TyOrConstInferVar};
use crate::traits::normalize::normalize_with_depth_to;
use crate::traits::normalize::normalize_with_depth_to_preresolved;
use crate::traits::project::{PolyProjectionObligation, ProjectionCacheKeyExt as _};
use crate::traits::query::evaluate_obligation::InferCtxtExt;
use crate::traits::{EvaluateConstErr, sizedness_fast_path};
Expand Down Expand Up @@ -401,7 +401,9 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {

if obligation.predicate.has_aliases() {
let mut obligations = PredicateObligations::new();
let predicate = normalize_with_depth_to(
// The predicate was already brought to its resolution fixpoint
// above, so normalization does not need to resolve it again.
let predicate = normalize_with_depth_to_preresolved(
&mut self.selcx,
obligation.param_env,
obligation.cause.clone(),
Expand Down
29 changes: 29 additions & 0 deletions compiler/rustc_trait_selection/src/traits/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ where
result
}

/// Like [`normalize_with_depth_to`], for values the caller has already brought
/// to their inference resolution fixpoint: the initial full resolving fold is
/// skipped, since it could not change the value.
pub(crate) fn normalize_with_depth_to_preresolved<'a, 'b, 'tcx, T>(
selcx: &'a mut SelectionContext<'b, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
cause: ObligationCause<'tcx>,
depth: usize,
value: T,
obligations: &mut PredicateObligations<'tcx>,
) -> T
where
T: TypeFoldable<TyCtxt<'tcx>>,
{
debug!(obligations.len = obligations.len());
let mut normalizer = AssocTypeNormalizer::new(selcx, param_env, cause, depth, obligations);
let result =
ensure_sufficient_stack(|| AssocTypeNormalizer::fold_preresolved(&mut normalizer, value));
debug!(?result, obligations.len = normalizer.obligations.len());
debug!(?normalizer.obligations,);
result
}

pub(super) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
infcx: &InferCtxt<'tcx>,
value: &T,
Expand Down Expand Up @@ -172,6 +195,12 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {

fn fold<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
let value = self.selcx.infcx.resolve_vars_if_possible(value);
self.fold_preresolved(value)
}

/// [`Self::fold`] for values already at their inference resolution
/// fixpoint, where the resolving fold would be the identity.
fn fold_preresolved<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
debug!(?value);

assert!(
Expand Down
Loading