Finish implementing RustcInternal
for TyKind
This will allow us to provide methods to create `Ty` inside the stable MIR, which can be helpful while handling pointers and other stuff.
This commit is contained in:
parent
efaf4258ba
commit
e19c7cd159
@ -9,7 +9,13 @@ use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy};
|
|||||||
use rustc_span::Symbol;
|
use rustc_span::Symbol;
|
||||||
use stable_mir::mir::alloc::AllocId;
|
use stable_mir::mir::alloc::AllocId;
|
||||||
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
|
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
|
||||||
use stable_mir::ty::{AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const, ExistentialTraitRef, FloatTy, GenericArgKind, GenericArgs, IndexedVal, IntTy, Region, RigidTy, Span, TraitRef, Ty, UintTy, VariantDef, VariantIdx};
|
use stable_mir::mir::{Mutability, Safety};
|
||||||
|
use stable_mir::ty::{
|
||||||
|
Abi, AdtDef, Binder, BoundRegionKind, BoundTyKind, BoundVariableKind, ClosureKind, Const,
|
||||||
|
DynKind, ExistentialPredicate, ExistentialProjection, ExistentialTraitRef, FloatTy, FnSig,
|
||||||
|
GenericArgKind, GenericArgs, IndexedVal, IntTy, Movability, Region, RigidTy, Span, TermKind,
|
||||||
|
TraitRef, Ty, UintTy, VariantDef, VariantIdx,
|
||||||
|
};
|
||||||
use stable_mir::{CrateItem, DefId};
|
use stable_mir::{CrateItem, DefId};
|
||||||
|
|
||||||
use super::RustcInternal;
|
use super::RustcInternal;
|
||||||
@ -80,17 +86,38 @@ impl<'tcx> RustcInternal<'tcx> for RigidTy {
|
|||||||
}
|
}
|
||||||
RigidTy::Str => rustc_ty::TyKind::Str,
|
RigidTy::Str => rustc_ty::TyKind::Str,
|
||||||
RigidTy::Slice(ty) => rustc_ty::TyKind::Slice(ty.internal(tables)),
|
RigidTy::Slice(ty) => rustc_ty::TyKind::Slice(ty.internal(tables)),
|
||||||
RigidTy::RawPtr(..)
|
RigidTy::RawPtr(ty, mutability) => rustc_ty::TyKind::RawPtr(rustc_ty::TypeAndMut {
|
||||||
| RigidTy::Ref(..)
|
ty: ty.internal(tables),
|
||||||
| RigidTy::Foreign(_)
|
mutbl: mutability.internal(tables),
|
||||||
| RigidTy::FnDef(_, _)
|
}),
|
||||||
| RigidTy::FnPtr(_)
|
RigidTy::Ref(region, ty, mutability) => rustc_ty::TyKind::Ref(
|
||||||
| RigidTy::Closure(..)
|
region.internal(tables),
|
||||||
| RigidTy::Coroutine(..)
|
ty.internal(tables),
|
||||||
| RigidTy::CoroutineWitness(..)
|
mutability.internal(tables),
|
||||||
| RigidTy::Dynamic(..)
|
),
|
||||||
| RigidTy::Tuple(..) => {
|
RigidTy::Foreign(def) => rustc_ty::TyKind::Foreign(def.0.internal(tables)),
|
||||||
todo!()
|
RigidTy::FnDef(def, args) => {
|
||||||
|
rustc_ty::TyKind::FnDef(def.0.internal(tables), args.internal(tables))
|
||||||
|
}
|
||||||
|
RigidTy::FnPtr(sig) => rustc_ty::TyKind::FnPtr(sig.internal(tables)),
|
||||||
|
RigidTy::Closure(def, args) => {
|
||||||
|
rustc_ty::TyKind::Closure(def.0.internal(tables), args.internal(tables))
|
||||||
|
}
|
||||||
|
RigidTy::Coroutine(def, args, mov) => rustc_ty::TyKind::Coroutine(
|
||||||
|
def.0.internal(tables),
|
||||||
|
args.internal(tables),
|
||||||
|
mov.internal(tables),
|
||||||
|
),
|
||||||
|
RigidTy::CoroutineWitness(def, args) => {
|
||||||
|
rustc_ty::TyKind::CoroutineWitness(def.0.internal(tables), args.internal(tables))
|
||||||
|
}
|
||||||
|
RigidTy::Dynamic(predicate, region, dyn_kind) => rustc_ty::TyKind::Dynamic(
|
||||||
|
tables.tcx.mk_poly_existential_predicates(&predicate.internal(tables)),
|
||||||
|
region.internal(tables),
|
||||||
|
dyn_kind.internal(tables),
|
||||||
|
),
|
||||||
|
RigidTy::Tuple(tys) => {
|
||||||
|
rustc_ty::TyKind::Tuple(tables.tcx.mk_type_list(&tys.internal(tables)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,6 +164,41 @@ impl<'tcx> RustcInternal<'tcx> for FloatTy {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for Mutability {
|
||||||
|
type T = rustc_ty::Mutability;
|
||||||
|
|
||||||
|
fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match self {
|
||||||
|
Mutability::Not => rustc_ty::Mutability::Not,
|
||||||
|
Mutability::Mut => rustc_ty::Mutability::Mut,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for Movability {
|
||||||
|
type T = rustc_ty::Movability;
|
||||||
|
|
||||||
|
fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match self {
|
||||||
|
Movability::Static => rustc_ty::Movability::Static,
|
||||||
|
Movability::Movable => rustc_ty::Movability::Movable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for FnSig {
|
||||||
|
type T = rustc_ty::FnSig<'tcx>;
|
||||||
|
|
||||||
|
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
rustc_ty::FnSig {
|
||||||
|
inputs_and_output: tables.tcx.mk_type_list(&self.inputs_and_output.internal(tables)),
|
||||||
|
c_variadic: self.c_variadic,
|
||||||
|
unsafety: self.unsafety.internal(tables),
|
||||||
|
abi: self.abi.internal(tables),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> RustcInternal<'tcx> for VariantIdx {
|
impl<'tcx> RustcInternal<'tcx> for VariantIdx {
|
||||||
type T = rustc_target::abi::VariantIdx;
|
type T = rustc_target::abi::VariantIdx;
|
||||||
|
|
||||||
@ -242,6 +304,58 @@ impl<'tcx> RustcInternal<'tcx> for BoundVariableKind {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for DynKind {
|
||||||
|
type T = rustc_ty::DynKind;
|
||||||
|
|
||||||
|
fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match self {
|
||||||
|
DynKind::Dyn => rustc_ty::DynKind::Dyn,
|
||||||
|
DynKind::DynStar => rustc_ty::DynKind::DynStar,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for ExistentialPredicate {
|
||||||
|
type T = rustc_ty::ExistentialPredicate<'tcx>;
|
||||||
|
|
||||||
|
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match self {
|
||||||
|
ExistentialPredicate::Trait(trait_ref) => {
|
||||||
|
rustc_ty::ExistentialPredicate::Trait(trait_ref.internal(tables))
|
||||||
|
}
|
||||||
|
ExistentialPredicate::Projection(proj) => {
|
||||||
|
rustc_ty::ExistentialPredicate::Projection(proj.internal(tables))
|
||||||
|
}
|
||||||
|
ExistentialPredicate::AutoTrait(trait_def) => {
|
||||||
|
rustc_ty::ExistentialPredicate::AutoTrait(trait_def.0.internal(tables))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for ExistentialProjection {
|
||||||
|
type T = rustc_ty::ExistentialProjection<'tcx>;
|
||||||
|
|
||||||
|
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
rustc_ty::ExistentialProjection {
|
||||||
|
def_id: self.def_id.0.internal(tables),
|
||||||
|
args: self.generic_args.internal(tables),
|
||||||
|
term: self.term.internal(tables),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for TermKind {
|
||||||
|
type T = rustc_ty::Term<'tcx>;
|
||||||
|
|
||||||
|
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match self {
|
||||||
|
TermKind::Type(ty) => ty.internal(tables).into(),
|
||||||
|
TermKind::Const(const_) => ty_const(const_, tables).into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> RustcInternal<'tcx> for ExistentialTraitRef {
|
impl<'tcx> RustcInternal<'tcx> for ExistentialTraitRef {
|
||||||
type T = rustc_ty::ExistentialTraitRef<'tcx>;
|
type T = rustc_ty::ExistentialTraitRef<'tcx>;
|
||||||
|
|
||||||
@ -291,6 +405,53 @@ impl<'tcx> RustcInternal<'tcx> for AdtDef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for Abi {
|
||||||
|
type T = rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
|
fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match *self {
|
||||||
|
Abi::Rust => rustc_target::spec::abi::Abi::Rust,
|
||||||
|
Abi::C { unwind } => rustc_target::spec::abi::Abi::C { unwind },
|
||||||
|
Abi::Cdecl { unwind } => rustc_target::spec::abi::Abi::Cdecl { unwind },
|
||||||
|
Abi::Stdcall { unwind } => rustc_target::spec::abi::Abi::Stdcall { unwind },
|
||||||
|
Abi::Fastcall { unwind } => rustc_target::spec::abi::Abi::Fastcall { unwind },
|
||||||
|
Abi::Vectorcall { unwind } => rustc_target::spec::abi::Abi::Vectorcall { unwind },
|
||||||
|
Abi::Thiscall { unwind } => rustc_target::spec::abi::Abi::Thiscall { unwind },
|
||||||
|
Abi::Aapcs { unwind } => rustc_target::spec::abi::Abi::Aapcs { unwind },
|
||||||
|
Abi::Win64 { unwind } => rustc_target::spec::abi::Abi::Win64 { unwind },
|
||||||
|
Abi::SysV64 { unwind } => rustc_target::spec::abi::Abi::SysV64 { unwind },
|
||||||
|
Abi::PtxKernel => rustc_target::spec::abi::Abi::PtxKernel,
|
||||||
|
Abi::Msp430Interrupt => rustc_target::spec::abi::Abi::Msp430Interrupt,
|
||||||
|
Abi::X86Interrupt => rustc_target::spec::abi::Abi::X86Interrupt,
|
||||||
|
Abi::AmdGpuKernel => rustc_target::spec::abi::Abi::AmdGpuKernel,
|
||||||
|
Abi::EfiApi => rustc_target::spec::abi::Abi::EfiApi,
|
||||||
|
Abi::AvrInterrupt => rustc_target::spec::abi::Abi::AvrInterrupt,
|
||||||
|
Abi::AvrNonBlockingInterrupt => rustc_target::spec::abi::Abi::AvrNonBlockingInterrupt,
|
||||||
|
Abi::CCmseNonSecureCall => rustc_target::spec::abi::Abi::CCmseNonSecureCall,
|
||||||
|
Abi::Wasm => rustc_target::spec::abi::Abi::Wasm,
|
||||||
|
Abi::System { unwind } => rustc_target::spec::abi::Abi::System { unwind },
|
||||||
|
Abi::RustIntrinsic => rustc_target::spec::abi::Abi::RustIntrinsic,
|
||||||
|
Abi::RustCall => rustc_target::spec::abi::Abi::RustCall,
|
||||||
|
Abi::PlatformIntrinsic => rustc_target::spec::abi::Abi::PlatformIntrinsic,
|
||||||
|
Abi::Unadjusted => rustc_target::spec::abi::Abi::Unadjusted,
|
||||||
|
Abi::RustCold => rustc_target::spec::abi::Abi::RustCold,
|
||||||
|
Abi::RiscvInterruptM => rustc_target::spec::abi::Abi::RiscvInterruptM,
|
||||||
|
Abi::RiscvInterruptS => rustc_target::spec::abi::Abi::RiscvInterruptS,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'tcx> RustcInternal<'tcx> for Safety {
|
||||||
|
type T = rustc_hir::Unsafety;
|
||||||
|
|
||||||
|
fn internal(&self, _tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
match self {
|
||||||
|
Safety::Unsafe => rustc_hir::Unsafety::Unsafe,
|
||||||
|
Safety::Normal => rustc_hir::Unsafety::Normal,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> RustcInternal<'tcx> for Span {
|
impl<'tcx> RustcInternal<'tcx> for Span {
|
||||||
type T = rustc_span::Span;
|
type T = rustc_span::Span;
|
||||||
|
|
||||||
@ -309,6 +470,7 @@ where
|
|||||||
(*self).internal(tables)
|
(*self).internal(tables)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx, T> RustcInternal<'tcx> for Option<T>
|
impl<'tcx, T> RustcInternal<'tcx> for Option<T>
|
||||||
where
|
where
|
||||||
T: RustcInternal<'tcx>,
|
T: RustcInternal<'tcx>,
|
||||||
@ -319,3 +481,14 @@ where
|
|||||||
self.as_ref().map(|inner| inner.internal(tables))
|
self.as_ref().map(|inner| inner.internal(tables))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx, T> RustcInternal<'tcx> for Vec<T>
|
||||||
|
where
|
||||||
|
T: RustcInternal<'tcx>,
|
||||||
|
{
|
||||||
|
type T = Vec<T::T>;
|
||||||
|
|
||||||
|
fn internal(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
self.iter().map(|e| e.internal(tables)).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -511,7 +511,7 @@ pub struct VarDebugInfo {
|
|||||||
pub name: Symbol,
|
pub name: Symbol,
|
||||||
|
|
||||||
/// Source info of the user variable, including the scope
|
/// Source info of the user variable, including the scope
|
||||||
/// within which the variable is visible (to debuginfo)
|
/// within which the variable is visible (to debuginfo).
|
||||||
pub source_info: SourceInfo,
|
pub source_info: SourceInfo,
|
||||||
|
|
||||||
/// The user variable's data is split across several fragments,
|
/// The user variable's data is split across several fragments,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user