Skip to content

Commit 412c6e0

Browse files
committed
review
1 parent a2dfed6 commit 412c6e0

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8383
/// version (resolve_vars_if_possible), this version will
8484
/// also select obligations if it seems useful, in an effort
8585
/// to get more type information.
86+
// FIXME(-Ztrait-solver=next): A lot of the calls to this method should
87+
// probably be `try_structurally_resolve_type` or `structurally_resolve_type` instead.
8688
pub(in super::super) fn resolve_vars_with_obligations(&self, ty: Ty<'tcx>) -> Ty<'tcx> {
8789
self.resolve_vars_with_obligations_and_mutate_fulfillment(ty, |_| {})
8890
}

compiler/rustc_trait_selection/src/solve/normalize.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::traits::error_reporting::TypeErrCtxtExt;
22
use crate::traits::query::evaluate_obligation::InferCtxtExt;
3-
use crate::traits::{needs_normalization, TraitEngineExt as _};
4-
use crate::traits::{BoundVarReplacer, PlaceholderReplacer};
3+
use crate::traits::{needs_normalization, BoundVarReplacer, PlaceholderReplacer};
54
use rustc_data_structures::stack::ensure_sufficient_stack;
65
use rustc_infer::infer::at::At;
76
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
@@ -13,22 +12,23 @@ use rustc_middle::ty::{self, AliasTy, Ty, TyCtxt, UniverseIndex};
1312
use rustc_middle::ty::{FallibleTypeFolder, TypeSuperFoldable};
1413
use rustc_middle::ty::{TypeFoldable, TypeVisitableExt};
1514

15+
use super::FulfillmentCtxt;
16+
1617
/// Deeply normalize all aliases in `value`. This does not handle inference and expects
1718
/// its input to be already fully resolved.
1819
pub(crate) fn deeply_normalize<'tcx, T: TypeFoldable<TyCtxt<'tcx>>>(
1920
at: At<'_, 'tcx>,
2021
value: T,
2122
) -> Result<T, Vec<FulfillmentError<'tcx>>> {
22-
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new(&at.infcx);
23-
let mut folder =
24-
NormalizationFolder { at, fulfill_cx: &mut *fulfill_cx, depth: 0, universes: Vec::new() };
23+
let fulfill_cx = FulfillmentCtxt::new();
24+
let mut folder = NormalizationFolder { at, fulfill_cx, depth: 0, universes: Vec::new() };
2525

2626
value.try_fold_with(&mut folder)
2727
}
2828

2929
struct NormalizationFolder<'me, 'tcx> {
3030
at: At<'me, 'tcx>,
31-
fulfill_cx: &'me mut dyn TraitEngine<'tcx>,
31+
fulfill_cx: FulfillmentCtxt<'tcx>,
3232
depth: usize,
3333
universes: Vec<Option<UniverseIndex>>,
3434
}
@@ -163,16 +163,14 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
163163
return Ok(ty);
164164
}
165165

166-
let (kind, data) = match *ty.kind() {
167-
ty::Alias(kind, alias_ty) => (kind, alias_ty),
168-
_ => return ty.try_super_fold_with(self),
169-
};
170-
171166
// We don't normalize opaque types unless we have
172167
// `Reveal::All`, even if we're in the defining scope.
173-
if matches!(kind, ty::Opaque) && reveal == Reveal::UserFacing {
174-
return ty.try_super_fold_with(self);
175-
}
168+
let data = match *ty.kind() {
169+
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::UserFacing => {
170+
alias_ty
171+
}
172+
_ => return ty.try_super_fold_with(self),
173+
};
176174

177175
if data.has_escaping_bound_vars() {
178176
let (data, mapped_regions, mapped_types, mapped_consts) =

compiler/rustc_trait_selection/src/traits/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,12 @@ pub fn normalize_param_env_or_error<'tcx>(
409409
)
410410
}
411411

412-
/// Normalize a type and process all resulting obligations, returning any errors
412+
/// Normalize a type and process all resulting obligations, returning any errors.
413+
///
414+
/// FIXME(-Ztrait-solver=next): This should be replaced by `At::deeply_normalize`
415+
/// which has the same behavior with the new solver. Because using a separate
416+
/// fulfillment context worsens caching in the old solver, `At::deeply_normalize`
417+
/// is still lazy with the old solver as it otherwise negatively impacts perf.
413418
#[instrument(skip_all)]
414419
pub fn fully_normalize<'tcx, T>(
415420
infcx: &InferCtxt<'tcx>,

compiler/rustc_trait_selection/src/traits/project.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,18 @@ pub trait NormalizeExt<'tcx> {
5858

5959
/// Deeply normalizes `value`, replacing all aliases which can by normalized in
6060
/// the current environment. In the new solver this errors in case normalization
61-
/// fails or is ambiguous. This only normalize opaque types with `Reveal::All`.
61+
/// fails or is ambiguous. This only normalizes opaque types with `Reveal::All`.
6262
///
6363
/// In the old solver this simply uses `normalizes` and adds the nested obligations
6464
/// to the `fulfill_cx`. This is necessary as we otherwise end up recomputing the
6565
/// same goals in both a temporary and the shared context which negatively impacts
6666
/// performance as these don't share caching.
67+
///
68+
/// FIXME(-Ztrait-solver=next): This has the same behavior as `traits::fully_normalize`
69+
/// in the new solver, but because of performance reasons, we currently reuse an
70+
/// existing fulfillment context in the old solver. Once we also eagerly prove goals with
71+
/// the old solver or have removed the old solver, remove `traits::fully_normalize` and
72+
/// rename this function to `At::fully_normalize`.
6773
fn deeply_normalize<T: TypeFoldable<TyCtxt<'tcx>>>(
6874
self,
6975
value: T,

0 commit comments

Comments
 (0)