1
Fork 0

split out AliasTy -> AliasTerm

This commit is contained in:
Michael Goulet 2024-05-13 10:00:38 -04:00
parent ecbe3fd550
commit 3bcdf3058e
70 changed files with 715 additions and 414 deletions

View file

@ -430,6 +430,20 @@ impl<'tcx> ToTrace<'tcx> for ty::TraitRef<'tcx> {
}
impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace {
cause: cause.clone(),
values: Aliases(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}
impl<'tcx> ToTrace<'tcx> for ty::AliasTerm<'tcx> {
fn to_trace(
cause: &ObligationCause<'tcx>,
a_is_expected: bool,

View file

@ -410,7 +410,7 @@ impl<'tcx> InferCtxt<'tcx> {
.kind()
.map_bound(|kind| match kind {
ty::ClauseKind::Projection(projection_predicate)
if projection_predicate.projection_ty.def_id == item_def_id =>
if projection_predicate.projection_term.def_id == item_def_id =>
{
projection_predicate.term.ty()
}

View file

@ -403,7 +403,7 @@ impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
pub enum ValuePairs<'tcx> {
Regions(ExpectedFound<ty::Region<'tcx>>),
Terms(ExpectedFound<ty::Term<'tcx>>),
Aliases(ExpectedFound<ty::AliasTy<'tcx>>),
Aliases(ExpectedFound<ty::AliasTerm<'tcx>>),
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
PolySigs(ExpectedFound<ty::PolyFnSig<'tcx>>),
ExistentialTraitRef(ExpectedFound<ty::PolyExistentialTraitRef<'tcx>>),

View file

@ -588,7 +588,7 @@ impl<'tcx> InferCtxt<'tcx> {
&& !tcx.is_impl_trait_in_trait(projection_ty.def_id)
&& !self.next_trait_solver() =>
{
self.infer_projection(
self.projection_ty_to_infer(
param_env,
projection_ty,
cause.clone(),

View file

@ -12,7 +12,7 @@ impl<'tcx> InferCtxt<'tcx> {
/// of the given projection. This allows us to proceed with projections
/// while they cannot be resolved yet due to missing information or
/// simply due to the lack of access to the trait resolution machinery.
pub fn infer_projection(
pub fn projection_ty_to_infer(
&self,
param_env: ty::ParamEnv<'tcx>,
projection_ty: ty::AliasTy<'tcx>,
@ -24,7 +24,7 @@ impl<'tcx> InferCtxt<'tcx> {
let def_id = projection_ty.def_id;
let ty_var = self.next_ty_var(self.tcx.def_span(def_id));
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(ty::ClauseKind::Projection(
ty::ProjectionPredicate { projection_ty, term: ty_var.into() },
ty::ProjectionPredicate { projection_term: projection_ty.into(), term: ty_var.into() },
)));
let obligation =
Obligation::with_depth(self.tcx, cause, recursion_depth, param_env, projection);

View file

@ -101,7 +101,7 @@ impl<'tcx> InferCtxt<'tcx> {
// instead create a new inference variable `?normalized_source`, emitting
// `Projection(normalized_source, ?ty_normalized)` and `?normalized_source <: generalized_ty`.
relation.register_predicates([ty::ProjectionPredicate {
projection_ty: data,
projection_term: data.into(),
term: generalized_ty.into(),
}]);
}

View file

@ -27,7 +27,7 @@ pub use self::engine::{TraitEngine, TraitEngineExt};
pub use self::project::MismatchedProjectionTypes;
pub(crate) use self::project::UndoLog;
pub use self::project::{
Normalized, NormalizedTy, ProjectionCache, ProjectionCacheEntry, ProjectionCacheKey,
Normalized, NormalizedTerm, ProjectionCache, ProjectionCacheEntry, ProjectionCacheKey,
ProjectionCacheStorage, Reveal,
};
pub use rustc_middle::traits::*;

View file

@ -8,7 +8,7 @@ use rustc_data_structures::{
snapshot_map::{self, SnapshotMapRef, SnapshotMapStorage},
undo_log::Rollback,
};
use rustc_middle::ty::{self, Ty};
use rustc_middle::ty;
pub use rustc_middle::traits::{EvaluationResult, Reveal};
@ -26,7 +26,7 @@ pub struct Normalized<'tcx, T> {
pub obligations: Vec<PredicateObligation<'tcx>>,
}
pub type NormalizedTy<'tcx> = Normalized<'tcx, Ty<'tcx>>;
pub type NormalizedTerm<'tcx> = Normalized<'tcx, ty::Term<'tcx>>;
impl<'tcx, T> Normalized<'tcx, T> {
pub fn with<U>(self, value: U) -> Normalized<'tcx, U> {
@ -77,13 +77,13 @@ pub struct ProjectionCacheStorage<'tcx> {
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct ProjectionCacheKey<'tcx> {
ty: ty::AliasTy<'tcx>,
term: ty::AliasTerm<'tcx>,
param_env: ty::ParamEnv<'tcx>,
}
impl<'tcx> ProjectionCacheKey<'tcx> {
pub fn new(ty: ty::AliasTy<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
Self { ty, param_env }
pub fn new(term: ty::AliasTerm<'tcx>, param_env: ty::ParamEnv<'tcx>) -> Self {
Self { term, param_env }
}
}
@ -94,7 +94,7 @@ pub enum ProjectionCacheEntry<'tcx> {
Recur,
Error,
NormalizedTy {
ty: Normalized<'tcx, ty::Term<'tcx>>,
ty: NormalizedTerm<'tcx>,
/// If we were able to successfully evaluate the
/// corresponding cache entry key during predicate
/// evaluation, then this field stores the final
@ -175,11 +175,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
}
/// Indicates that `key` was normalized to `value`.
pub fn insert_term(
&mut self,
key: ProjectionCacheKey<'tcx>,
value: Normalized<'tcx, ty::Term<'tcx>>,
) {
pub fn insert_term(&mut self, key: ProjectionCacheKey<'tcx>, value: NormalizedTerm<'tcx>) {
debug!(
"ProjectionCacheEntry::insert_ty: adding cache entry: key={:?}, value={:?}",
key, value