Auto merge of #125076 - compiler-errors:alias-term, r=lcnr
Split out `ty::AliasTerm` from `ty::AliasTy` Splitting out `AliasTerm` (for use in project and normalizes goals) and `AliasTy` (for use in `ty::Alias`) r? lcnr
This commit is contained in:
commit
34582118af
73 changed files with 695 additions and 458 deletions
|
@ -431,6 +431,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,
|
||||
|
|
|
@ -411,7 +411,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()
|
||||
}
|
||||
|
|
|
@ -404,7 +404,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>>),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -102,7 +102,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(),
|
||||
}]);
|
||||
}
|
||||
|
|
|
@ -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::*;
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,8 +93,8 @@ pub enum ProjectionCacheEntry<'tcx> {
|
|||
Ambiguous,
|
||||
Recur,
|
||||
Error,
|
||||
NormalizedTy {
|
||||
ty: Normalized<'tcx, ty::Term<'tcx>>,
|
||||
NormalizedTerm {
|
||||
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
|
||||
|
@ -190,7 +186,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||
return;
|
||||
}
|
||||
let fresh_key =
|
||||
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty: value, complete: None });
|
||||
map.insert(key, ProjectionCacheEntry::NormalizedTerm { ty: value, complete: None });
|
||||
assert!(!fresh_key, "never started projecting `{key:?}`");
|
||||
}
|
||||
|
||||
|
@ -201,13 +197,16 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||
pub fn complete(&mut self, key: ProjectionCacheKey<'tcx>, result: EvaluationResult) {
|
||||
let mut map = self.map();
|
||||
match map.get(&key) {
|
||||
Some(ProjectionCacheEntry::NormalizedTy { ty, complete: _ }) => {
|
||||
Some(ProjectionCacheEntry::NormalizedTerm { ty, complete: _ }) => {
|
||||
info!("ProjectionCacheEntry::complete({:?}) - completing {:?}", key, ty);
|
||||
let mut ty = ty.clone();
|
||||
if result.must_apply_considering_regions() {
|
||||
ty.obligations = vec![];
|
||||
}
|
||||
map.insert(key, ProjectionCacheEntry::NormalizedTy { ty, complete: Some(result) });
|
||||
map.insert(
|
||||
key,
|
||||
ProjectionCacheEntry::NormalizedTerm { ty, complete: Some(result) },
|
||||
);
|
||||
}
|
||||
ref value => {
|
||||
// Type inference could "strand behind" old cache entries. Leave
|
||||
|
@ -219,7 +218,7 @@ impl<'tcx> ProjectionCache<'_, 'tcx> {
|
|||
|
||||
pub fn is_complete(&mut self, key: ProjectionCacheKey<'tcx>) -> Option<EvaluationResult> {
|
||||
self.map().get(&key).and_then(|res| match res {
|
||||
ProjectionCacheEntry::NormalizedTy { ty: _, complete } => *complete,
|
||||
ProjectionCacheEntry::NormalizedTerm { ty: _, complete } => *complete,
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue