canonicalization
This commit is contained in:
parent
13471d3b20
commit
a15abea931
13 changed files with 805 additions and 88 deletions
|
@ -369,6 +369,34 @@ impl<'tcx> ToTrace<'tcx> for Const<'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToTrace<'tcx> for ty::GenericArg<'tcx> {
|
||||
fn to_trace(
|
||||
_: TyCtxt<'tcx>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
a_is_expected: bool,
|
||||
a: Self,
|
||||
b: Self,
|
||||
) -> TypeTrace<'tcx> {
|
||||
use GenericArgKind::*;
|
||||
TypeTrace {
|
||||
cause: cause.clone(),
|
||||
values: match (a.unpack(), b.unpack()) {
|
||||
(Lifetime(a), Lifetime(b)) => Regions(ExpectedFound::new(a_is_expected, a, b)),
|
||||
(Type(a), Type(b)) => Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
||||
(Const(a), Const(b)) => {
|
||||
Terms(ExpectedFound::new(a_is_expected, a.into(), b.into()))
|
||||
}
|
||||
|
||||
(Lifetime(_), Type(_) | Const(_))
|
||||
| (Type(_), Lifetime(_) | Const(_))
|
||||
| (Const(_), Lifetime(_) | Type(_)) => {
|
||||
bug!("relating different kinds: {a:?} {b:?}")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
|
||||
fn to_trace(
|
||||
_: TyCtxt<'tcx>,
|
||||
|
|
|
@ -30,7 +30,7 @@ use rustc_middle::ty::{self, List, TyCtxt};
|
|||
use rustc_span::source_map::Span;
|
||||
|
||||
pub use rustc_middle::infer::canonical::*;
|
||||
use substitute::CanonicalExt;
|
||||
pub use substitute::CanonicalExt;
|
||||
|
||||
mod canonicalizer;
|
||||
pub mod query_response;
|
||||
|
@ -100,7 +100,11 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
/// variable for it. If this is an existentially quantified
|
||||
/// variable, then you'll get a new inference variable; if it is a
|
||||
/// universally quantified variable, you get a placeholder.
|
||||
fn instantiate_canonical_var(
|
||||
///
|
||||
/// FIXME(-Ztrait-solver=next): This is public because it's used by the
|
||||
/// new trait solver which has a different canonicalization routine.
|
||||
/// We should somehow deduplicate all of this.
|
||||
pub fn instantiate_canonical_var(
|
||||
&self,
|
||||
span: Span,
|
||||
cv_info: CanonicalVarInfo<'tcx>,
|
||||
|
|
|
@ -151,11 +151,21 @@ impl<'tcx> InferCtxt<'tcx> {
|
|||
})
|
||||
}
|
||||
|
||||
/// FIXME: This method should only be used for canonical queries and therefore be private.
|
||||
///
|
||||
/// As the new solver does canonicalization slightly differently, this is also used there
|
||||
/// for now. This should hopefully change fairly soon.
|
||||
pub fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
|
||||
/// Used by the new solver as that one takes the opaque types at the end of a probe
|
||||
/// to deal with multiple candidates without having to recompute them.
|
||||
pub fn clone_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
|
||||
self.inner
|
||||
.borrow()
|
||||
.opaque_type_storage
|
||||
.opaque_types
|
||||
.iter()
|
||||
.map(|&(k, ref v)| {
|
||||
(self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn take_opaque_types_for_query_response(&self) -> Vec<(Ty<'tcx>, Ty<'tcx>)> {
|
||||
std::mem::take(&mut self.inner.borrow_mut().opaque_type_storage.opaque_types)
|
||||
.into_iter()
|
||||
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
|
||||
|
|
|
@ -11,7 +11,9 @@ use rustc_middle::ty::fold::{FnMutDelegate, TypeFoldable};
|
|||
use rustc_middle::ty::subst::GenericArgKind;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
|
||||
pub(super) trait CanonicalExt<'tcx, V> {
|
||||
/// FIXME(-Ztrait-solver=next): This or public because it is shared with the
|
||||
/// new trait solver implementation. We should deduplicate canonicalization.
|
||||
pub trait CanonicalExt<'tcx, V> {
|
||||
/// Instantiate the wrapped value, replacing each canonical value
|
||||
/// with the value given in `var_values`.
|
||||
fn substitute(&self, tcx: TyCtxt<'tcx>, var_values: &CanonicalVarValues<'tcx>) -> V
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue