never normalize without eager inference replacement
This commit is contained in:
parent
bea5bebf3d
commit
486c7b6a50
3 changed files with 11 additions and 82 deletions
|
@ -312,7 +312,7 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
|
||||||
|
|
||||||
if obligation.predicate.has_projections() {
|
if obligation.predicate.has_projections() {
|
||||||
let mut obligations = Vec::new();
|
let mut obligations = Vec::new();
|
||||||
let predicate = crate::traits::project::try_normalize_with_depth_to(
|
let predicate = crate::traits::project::normalize_with_depth_to(
|
||||||
&mut self.selcx,
|
&mut self.selcx,
|
||||||
obligation.param_env,
|
obligation.param_env,
|
||||||
obligation.cause.clone(),
|
obligation.cause.clone(),
|
||||||
|
|
|
@ -374,32 +374,6 @@ where
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "info", skip(selcx, param_env, cause, obligations))]
|
|
||||||
pub(crate) fn try_normalize_with_depth_to<'a, 'b, 'tcx, T>(
|
|
||||||
selcx: &'a mut SelectionContext<'b, 'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
cause: ObligationCause<'tcx>,
|
|
||||||
depth: usize,
|
|
||||||
value: T,
|
|
||||||
obligations: &mut Vec<PredicateObligation<'tcx>>,
|
|
||||||
) -> T
|
|
||||||
where
|
|
||||||
T: TypeFoldable<TyCtxt<'tcx>>,
|
|
||||||
{
|
|
||||||
debug!(obligations.len = obligations.len());
|
|
||||||
let mut normalizer = AssocTypeNormalizer::new_without_eager_inference_replacement(
|
|
||||||
selcx,
|
|
||||||
param_env,
|
|
||||||
cause,
|
|
||||||
depth,
|
|
||||||
obligations,
|
|
||||||
);
|
|
||||||
let result = ensure_sufficient_stack(|| normalizer.fold(value));
|
|
||||||
debug!(?result, obligations.len = normalizer.obligations.len());
|
|
||||||
debug!(?normalizer.obligations,);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
|
pub(crate) fn needs_normalization<'tcx, T: TypeVisitable<TyCtxt<'tcx>>>(
|
||||||
value: &T,
|
value: &T,
|
||||||
reveal: Reveal,
|
reveal: Reveal,
|
||||||
|
@ -426,10 +400,6 @@ struct AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||||
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
||||||
depth: usize,
|
depth: usize,
|
||||||
universes: Vec<Option<ty::UniverseIndex>>,
|
universes: Vec<Option<ty::UniverseIndex>>,
|
||||||
/// If true, when a projection is unable to be completed, an inference
|
|
||||||
/// variable will be created and an obligation registered to project to that
|
|
||||||
/// inference variable. Also, constants will be eagerly evaluated.
|
|
||||||
eager_inference_replacement: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||||
|
@ -441,33 +411,7 @@ impl<'a, 'b, 'tcx> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||||
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
||||||
) -> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
) -> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
||||||
debug_assert!(!selcx.infcx.next_trait_solver());
|
debug_assert!(!selcx.infcx.next_trait_solver());
|
||||||
AssocTypeNormalizer {
|
AssocTypeNormalizer { selcx, param_env, cause, obligations, depth, universes: vec![] }
|
||||||
selcx,
|
|
||||||
param_env,
|
|
||||||
cause,
|
|
||||||
obligations,
|
|
||||||
depth,
|
|
||||||
universes: vec![],
|
|
||||||
eager_inference_replacement: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_without_eager_inference_replacement(
|
|
||||||
selcx: &'a mut SelectionContext<'b, 'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
cause: ObligationCause<'tcx>,
|
|
||||||
depth: usize,
|
|
||||||
obligations: &'a mut Vec<PredicateObligation<'tcx>>,
|
|
||||||
) -> AssocTypeNormalizer<'a, 'b, 'tcx> {
|
|
||||||
AssocTypeNormalizer {
|
|
||||||
selcx,
|
|
||||||
param_env,
|
|
||||||
cause,
|
|
||||||
obligations,
|
|
||||||
depth,
|
|
||||||
universes: vec![],
|
|
||||||
eager_inference_replacement: false,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn fold<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
|
fn fold<T: TypeFoldable<TyCtxt<'tcx>>>(&mut self, value: T) -> T {
|
||||||
|
@ -570,28 +514,14 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
||||||
// register an obligation to *later* project, since we know
|
// register an obligation to *later* project, since we know
|
||||||
// there won't be bound vars there.
|
// there won't be bound vars there.
|
||||||
let data = data.fold_with(self);
|
let data = data.fold_with(self);
|
||||||
let normalized_ty = if self.eager_inference_replacement {
|
let normalized_ty = normalize_projection_type(
|
||||||
normalize_projection_type(
|
|
||||||
self.selcx,
|
self.selcx,
|
||||||
self.param_env,
|
self.param_env,
|
||||||
data,
|
data,
|
||||||
self.cause.clone(),
|
self.cause.clone(),
|
||||||
self.depth,
|
self.depth,
|
||||||
self.obligations,
|
self.obligations,
|
||||||
)
|
);
|
||||||
} else {
|
|
||||||
opt_normalize_projection_type(
|
|
||||||
self.selcx,
|
|
||||||
self.param_env,
|
|
||||||
data,
|
|
||||||
self.cause.clone(),
|
|
||||||
self.depth,
|
|
||||||
self.obligations,
|
|
||||||
)
|
|
||||||
.ok()
|
|
||||||
.flatten()
|
|
||||||
.unwrap_or_else(|| ty.super_fold_with(self).into())
|
|
||||||
};
|
|
||||||
debug!(
|
debug!(
|
||||||
?self.depth,
|
?self.depth,
|
||||||
?ty,
|
?ty,
|
||||||
|
|
|
@ -22,7 +22,6 @@ use super::{
|
||||||
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
|
use crate::infer::{InferCtxt, InferOk, TypeFreshener};
|
||||||
use crate::solve::InferCtxtSelectExt;
|
use crate::solve::InferCtxtSelectExt;
|
||||||
use crate::traits::error_reporting::TypeErrCtxtExt;
|
use crate::traits::error_reporting::TypeErrCtxtExt;
|
||||||
use crate::traits::project::try_normalize_with_depth_to;
|
|
||||||
use crate::traits::project::ProjectAndUnifyResult;
|
use crate::traits::project::ProjectAndUnifyResult;
|
||||||
use crate::traits::project::ProjectionCacheKeyExt;
|
use crate::traits::project::ProjectionCacheKeyExt;
|
||||||
use crate::traits::ProjectionCacheKey;
|
use crate::traits::ProjectionCacheKey;
|
||||||
|
@ -1070,7 +1069,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
&& fresh_trait_pred.is_global()
|
&& fresh_trait_pred.is_global()
|
||||||
{
|
{
|
||||||
let mut nested_obligations = Vec::new();
|
let mut nested_obligations = Vec::new();
|
||||||
let predicate = try_normalize_with_depth_to(
|
let predicate = normalize_with_depth_to(
|
||||||
this,
|
this,
|
||||||
param_env,
|
param_env,
|
||||||
obligation.cause.clone(),
|
obligation.cause.clone(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue