Uplift canonicalizer into new trait solver crate
This commit is contained in:
parent
ae612bedcb
commit
cb41509601
20 changed files with 507 additions and 273 deletions
|
@ -7,7 +7,7 @@ use rustc_hir as hir;
|
|||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_macros::HashStable;
|
||||
use rustc_type_ir::{TypeFlags, WithCachedTypeInfo};
|
||||
use rustc_type_ir::{ConstTy, IntoKind, TypeFlags, WithCachedTypeInfo};
|
||||
|
||||
mod int;
|
||||
mod kind;
|
||||
|
@ -26,6 +26,20 @@ use super::sty::ConstKind;
|
|||
#[rustc_pass_by_value]
|
||||
pub struct Const<'tcx>(pub(super) Interned<'tcx, WithCachedTypeInfo<ConstData<'tcx>>>);
|
||||
|
||||
impl<'tcx> IntoKind for Const<'tcx> {
|
||||
type Kind = ConstKind<'tcx>;
|
||||
|
||||
fn kind(&self) -> ConstKind<'tcx> {
|
||||
(*self).kind().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ConstTy<TyCtxt<'tcx>> for Const<'tcx> {
|
||||
fn ty(&self) -> Ty<'tcx> {
|
||||
(*self).ty()
|
||||
}
|
||||
}
|
||||
|
||||
/// Typed constant value.
|
||||
#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, HashStable, TyEncodable, TyDecodable)]
|
||||
pub struct ConstData<'tcx> {
|
||||
|
|
|
@ -131,6 +131,42 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
|
|||
) -> (Self::Ty, ty::Mutability) {
|
||||
(ty, mutbl)
|
||||
}
|
||||
|
||||
fn mk_canonical_var_infos(
|
||||
&self,
|
||||
infos: &[rustc_type_ir::CanonicalVarInfo<Self>],
|
||||
) -> Self::CanonicalVars {
|
||||
(*self).mk_canonical_var_infos(infos)
|
||||
}
|
||||
|
||||
fn mk_bound_ty(
|
||||
&self,
|
||||
debruijn: rustc_type_ir::DebruijnIndex,
|
||||
var: rustc_type_ir::BoundVar,
|
||||
) -> Self::Ty {
|
||||
Ty::new_bound(*self, debruijn, ty::BoundTy { var, kind: ty::BoundTyKind::Anon })
|
||||
}
|
||||
|
||||
fn mk_bound_region(
|
||||
&self,
|
||||
debruijn: rustc_type_ir::DebruijnIndex,
|
||||
var: rustc_type_ir::BoundVar,
|
||||
) -> Self::Region {
|
||||
Region::new_bound(
|
||||
*self,
|
||||
debruijn,
|
||||
ty::BoundRegion { var, kind: ty::BoundRegionKind::BrAnon },
|
||||
)
|
||||
}
|
||||
|
||||
fn mk_bound_const(
|
||||
&self,
|
||||
debruijn: rustc_type_ir::DebruijnIndex,
|
||||
var: rustc_type_ir::BoundVar,
|
||||
ty: Self::Ty,
|
||||
) -> Self::Const {
|
||||
Const::new_bound(*self, debruijn, var, ty)
|
||||
}
|
||||
}
|
||||
|
||||
type InternedSet<'tcx, T> = ShardedHashMap<InternedInSet<'tcx, T>, ()>;
|
||||
|
|
|
@ -474,6 +474,14 @@ pub struct CReaderCacheKey {
|
|||
#[rustc_pass_by_value]
|
||||
pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
|
||||
|
||||
impl<'tcx> IntoKind for Ty<'tcx> {
|
||||
type Kind = TyKind<'tcx>;
|
||||
|
||||
fn kind(&self) -> TyKind<'tcx> {
|
||||
(*self).kind().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl EarlyParamRegion {
|
||||
/// Does this early bound region have a name? Early bound regions normally
|
||||
/// always have names except when using anonymous lifetimes (`'_`).
|
||||
|
@ -1554,8 +1562,12 @@ impl rustc_type_ir::Placeholder for PlaceholderRegion {
|
|||
self.bound.var
|
||||
}
|
||||
|
||||
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..self }
|
||||
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..*self }
|
||||
}
|
||||
|
||||
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: BoundRegion { var, kind: BoundRegionKind::BrAnon } }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1570,8 +1582,12 @@ impl rustc_type_ir::Placeholder for PlaceholderType {
|
|||
self.bound.var
|
||||
}
|
||||
|
||||
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..self }
|
||||
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..*self }
|
||||
}
|
||||
|
||||
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: BoundTy { var, kind: BoundTyKind::Anon } }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1593,8 +1609,12 @@ impl rustc_type_ir::Placeholder for PlaceholderConst {
|
|||
self.bound
|
||||
}
|
||||
|
||||
fn with_updated_universe(self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..self }
|
||||
fn with_updated_universe(&self, ui: UniverseIndex) -> Self {
|
||||
Placeholder { universe: ui, ..*self }
|
||||
}
|
||||
|
||||
fn new(ui: UniverseIndex, var: BoundVar) -> Self {
|
||||
Placeholder { universe: ui, bound: var }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ use crate::infer::canonical::Canonical;
|
|||
use crate::ty::visit::ValidateBoundVars;
|
||||
use crate::ty::InferTy::*;
|
||||
use crate::ty::{
|
||||
self, AdtDef, Discr, Term, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable,
|
||||
self, AdtDef, Discr, IntoKind, Term, Ty, TyCtxt, TypeFlags, TypeSuperVisitable, TypeVisitable,
|
||||
TypeVisitableExt, TypeVisitor,
|
||||
};
|
||||
use crate::ty::{GenericArg, GenericArgs, GenericArgsRef};
|
||||
|
@ -1477,6 +1477,14 @@ impl ParamConst {
|
|||
#[rustc_pass_by_value]
|
||||
pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
|
||||
|
||||
impl<'tcx> IntoKind for Region<'tcx> {
|
||||
type Kind = RegionKind<'tcx>;
|
||||
|
||||
fn kind(&self) -> RegionKind<'tcx> {
|
||||
**self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> Region<'tcx> {
|
||||
#[inline]
|
||||
pub fn new_early_param(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue