Rename some normalization-related items

This commit is contained in:
León Orell Valerian Liehr 2024-02-20 10:34:51 +01:00
parent 5af2130440
commit 05ce209d20
No known key found for this signature in database
GPG Key ID: D17A07215F68E713
6 changed files with 51 additions and 40 deletions

View File

@ -47,7 +47,7 @@ macro_rules! arena_types {
rustc_middle::traits::query::DropckOutlivesResult<'tcx> rustc_middle::traits::query::DropckOutlivesResult<'tcx>
> >
>, >,
[] normalize_projection_ty: [] normalize_canonicalized_projection_ty:
rustc_middle::infer::canonical::Canonical<'tcx, rustc_middle::infer::canonical::Canonical<'tcx,
rustc_middle::infer::canonical::QueryResponse<'tcx, rustc_middle::infer::canonical::QueryResponse<'tcx,
rustc_middle::traits::query::NormalizationResult<'tcx> rustc_middle::traits::query::NormalizationResult<'tcx>

View File

@ -31,7 +31,7 @@ use crate::query::plumbing::{
}; };
use crate::thir; use crate::thir;
use crate::traits::query::{ use crate::traits::query::{
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal, CanonicalAliasGoal, CanonicalPredicateGoal, CanonicalTyGoal,
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal, CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal, NoSolution, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal, NoSolution,
}; };
@ -1931,9 +1931,13 @@ rustc_queries! {
arena_cache arena_cache
} }
/// Do not call this query directly: invoke `normalize` instead. /// <div class="warning">
query normalize_projection_ty( ///
goal: CanonicalProjectionGoal<'tcx> /// Do not call this query directly: Invoke `normalize` instead.
///
/// </div>
query normalize_canonicalized_projection_ty(
goal: CanonicalAliasGoal<'tcx>
) -> Result< ) -> Result<
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>, &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
NoSolution, NoSolution,
@ -1941,9 +1945,13 @@ rustc_queries! {
desc { "normalizing `{}`", goal.value.value } desc { "normalizing `{}`", goal.value.value }
} }
/// Do not call this query directly: invoke `normalize` instead. /// <div class="warning">
query normalize_weak_ty( ///
goal: CanonicalProjectionGoal<'tcx> /// Do not call this query directly: Invoke `normalize` instead.
///
/// </div>
query normalize_canonicalized_weak_ty(
goal: CanonicalAliasGoal<'tcx>
) -> Result< ) -> Result<
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>, &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
NoSolution, NoSolution,
@ -1951,9 +1959,13 @@ rustc_queries! {
desc { "normalizing `{}`", goal.value.value } desc { "normalizing `{}`", goal.value.value }
} }
/// Do not call this query directly: invoke `normalize` instead. /// <div class="warning">
query normalize_inherent_projection_ty( ///
goal: CanonicalProjectionGoal<'tcx> /// Do not call this query directly: Invoke `normalize` instead.
///
/// </div>
query normalize_canonicalized_inherent_projection_ty(
goal: CanonicalAliasGoal<'tcx>
) -> Result< ) -> Result<
&'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>, &'tcx Canonical<'tcx, canonical::QueryResponse<'tcx, NormalizationResult<'tcx>>>,
NoSolution, NoSolution,

View File

@ -67,7 +67,7 @@ pub mod type_op {
} }
} }
pub type CanonicalProjectionGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>; pub type CanonicalAliasGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, ty::AliasTy<'tcx>>>;
pub type CanonicalTyGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, Ty<'tcx>>>; pub type CanonicalTyGoal<'tcx> = Canonical<'tcx, ty::ParamEnvAnd<'tcx, Ty<'tcx>>>;
@ -177,10 +177,10 @@ pub struct MethodAutoderefBadTy<'tcx> {
pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>, pub ty: Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
} }
/// Result from the `normalize_projection_ty` query. /// Result of the `normalize_canonicalized_{{,inherent_}projection,weak}_ty` queries.
#[derive(Clone, Debug, HashStable, TypeFoldable, TypeVisitable)] #[derive(Clone, Debug, HashStable, TypeFoldable, TypeVisitable)]
pub struct NormalizationResult<'tcx> { pub struct NormalizationResult<'tcx> {
/// Result of normalization. /// Result of the normalization.
pub normalized_ty: Ty<'tcx>, pub normalized_ty: Ty<'tcx>,
} }

View File

@ -355,8 +355,6 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
let data = data.fold_with(self); let data = data.fold_with(self);
// FIXME(inherent_associated_types): Do we need to honor `self.eager_inference_replacement`
// here like `ty::Projection`?
project::normalize_inherent_projection( project::normalize_inherent_projection(
self.selcx, self.selcx,
self.param_env, self.param_env,

View File

@ -1,6 +1,6 @@
//! Code for the 'normalization' query. This consists of a wrapper //! Code for the 'normalization' query. This consists of a wrapper
//! which folds deeply, invoking the underlying //! which folds deeply, invoking the underlying
//! `normalize_projection_ty` query when it encounters projections. //! `normalize_canonicalized_projection_ty` query when it encounters projections.
use crate::infer::at::At; use crate::infer::at::At;
use crate::infer::canonical::OriginalQueryValues; use crate::infer::canonical::OriginalQueryValues;
@ -271,9 +271,9 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
debug!("QueryNormalizer: c_data = {:#?}", c_data); debug!("QueryNormalizer: c_data = {:#?}", c_data);
debug!("QueryNormalizer: orig_values = {:#?}", orig_values); debug!("QueryNormalizer: orig_values = {:#?}", orig_values);
let result = match kind { let result = match kind {
ty::Projection => tcx.normalize_projection_ty(c_data), ty::Projection => tcx.normalize_canonicalized_projection_ty(c_data),
ty::Weak => tcx.normalize_weak_ty(c_data), ty::Weak => tcx.normalize_canonicalized_weak_ty(c_data),
ty::Inherent => tcx.normalize_inherent_projection_ty(c_data), ty::Inherent => tcx.normalize_canonicalized_inherent_projection_ty(c_data),
kind => unreachable!("did not expect {kind:?} due to match arm above"), kind => unreachable!("did not expect {kind:?} due to match arm above"),
}?; }?;
// We don't expect ambiguity. // We don't expect ambiguity.
@ -308,10 +308,10 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
} else { } else {
result.normalized_ty result.normalized_ty
}; };
// `tcx.normalize_projection_ty` may normalize to a type that still has // `tcx.normalize_canonicalized_projection_ty` may normalize to a type that
// unevaluated consts, so keep normalizing here if that's the case. // still has unevaluated consts, so keep normalizing here if that's the case.
// Similarly, `tcx.normalize_weak_ty` will only unwrap one layer of type // Similarly, `tcx.normalize_canonicalized_weak_ty` will only unwrap one layer
// and we need to continue folding it to reveal the TAIT behind it. // of type and we need to continue folding it to reveal the TAIT behind it.
if res != ty if res != ty
&& (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) || kind == ty::Weak) && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) || kind == ty::Weak)
{ {

View File

@ -5,7 +5,7 @@ use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
use rustc_trait_selection::infer::InferCtxtBuilderExt; use rustc_trait_selection::infer::InferCtxtBuilderExt;
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt;
use rustc_trait_selection::traits::query::{ use rustc_trait_selection::traits::query::{
normalize::NormalizationResult, CanonicalProjectionGoal, NoSolution, normalize::NormalizationResult, CanonicalAliasGoal, NoSolution,
}; };
use rustc_trait_selection::traits::{ use rustc_trait_selection::traits::{
self, FulfillmentErrorCode, ObligationCause, SelectionContext, self, FulfillmentErrorCode, ObligationCause, SelectionContext,
@ -13,18 +13,19 @@ use rustc_trait_selection::traits::{
pub(crate) fn provide(p: &mut Providers) { pub(crate) fn provide(p: &mut Providers) {
*p = Providers { *p = Providers {
normalize_projection_ty, normalize_canonicalized_projection_ty,
normalize_weak_ty, normalize_canonicalized_weak_ty,
normalize_inherent_projection_ty, normalize_canonicalized_inherent_projection_ty,
..*p ..*p
}; };
} }
fn normalize_projection_ty<'tcx>( fn normalize_canonicalized_projection_ty<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
goal: CanonicalProjectionGoal<'tcx>, goal: CanonicalAliasGoal<'tcx>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> { ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
debug!("normalize_provider(goal={:#?})", goal); debug!("normalize_canonicalized_projection_ty(goal={:#?})", goal);
tcx.infer_ctxt().enter_canonical_trait_query( tcx.infer_ctxt().enter_canonical_trait_query(
&goal, &goal,
|ocx, ParamEnvAnd { param_env, value: goal }| { |ocx, ParamEnvAnd { param_env, value: goal }| {
@ -61,19 +62,19 @@ fn normalize_projection_ty<'tcx>(
return Err(NoSolution); return Err(NoSolution);
} }
// FIXME(associated_const_equality): All users of normalize_projection_ty expected // FIXME(associated_const_equality): All users of normalize_canonicalized_projection_ty
// a type, but there is the possibility it could've been a const now. Maybe change // expected a type, but there is the possibility it could've been a const now.
// it to a Term later? // Maybe change it to a Term later?
Ok(NormalizationResult { normalized_ty: answer.ty().unwrap() }) Ok(NormalizationResult { normalized_ty: answer.ty().unwrap() })
}, },
) )
} }
fn normalize_weak_ty<'tcx>( fn normalize_canonicalized_weak_ty<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
goal: CanonicalProjectionGoal<'tcx>, goal: CanonicalAliasGoal<'tcx>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> { ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
debug!("normalize_provider(goal={:#?})", goal); debug!("normalize_canonicalized_weak_ty(goal={:#?})", goal);
tcx.infer_ctxt().enter_canonical_trait_query( tcx.infer_ctxt().enter_canonical_trait_query(
&goal, &goal,
@ -95,11 +96,11 @@ fn normalize_weak_ty<'tcx>(
) )
} }
fn normalize_inherent_projection_ty<'tcx>( fn normalize_canonicalized_inherent_projection_ty<'tcx>(
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
goal: CanonicalProjectionGoal<'tcx>, goal: CanonicalAliasGoal<'tcx>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> { ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, NormalizationResult<'tcx>>>, NoSolution> {
debug!("normalize_provider(goal={:#?})", goal); debug!("normalize_canonicalized_inherent_projection_ty(goal={:#?})", goal);
tcx.infer_ctxt().enter_canonical_trait_query( tcx.infer_ctxt().enter_canonical_trait_query(
&goal, &goal,