2023-10-19 17:06:53 -07:00
|
|
|
//! Module containing the translation from stable mir constructs to the rustc counterpart.
|
|
|
|
|
//!
|
|
|
|
|
//! This module will only include a few constructs to allow users to invoke internal rustc APIs
|
|
|
|
|
//! due to incomplete stable coverage.
|
|
|
|
|
|
|
|
|
|
// Prefer importing stable_mir over internal rustc constructs to make this file more readable.
|
2023-10-23 20:32:31 -07:00
|
|
|
use crate::rustc_smir::Tables;
|
2024-01-17 18:35:19 -08:00
|
|
|
use rustc_middle::ty::{self as rustc_ty, Ty as InternalTy, TyCtxt};
|
2023-11-07 14:07:32 -08:00
|
|
|
use rustc_span::Symbol;
|
2023-12-18 19:52:25 +00:00
|
|
|
use stable_mir::abi::Layout;
|
2023-11-07 14:12:58 -08:00
|
|
|
use stable_mir::mir::alloc::AllocId;
|
2023-11-07 14:07:32 -08:00
|
|
|
use stable_mir::mir::mono::{Instance, MonoItem, StaticDef};
|
2023-12-01 11:38:42 -08:00
|
|
|
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,
|
|
|
|
|
};
|
2024-01-09 15:45:03 -08:00
|
|
|
use stable_mir::{CrateItem, CrateNum, DefId};
|
2023-10-19 17:06:53 -07:00
|
|
|
|
|
|
|
|
use super::RustcInternal;
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for CrateItem {
|
|
|
|
|
type T<'tcx> = rustc_span::def_id::DefId;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
self.0.internal(tables, tcx)
|
2023-11-07 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for CrateNum {
|
|
|
|
|
type T<'tcx> = rustc_span::def_id::CrateNum;
|
|
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-09 15:45:03 -08:00
|
|
|
rustc_span::def_id::CrateNum::from_usize(*self)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for DefId {
|
|
|
|
|
type T<'tcx> = rustc_span::def_id::DefId;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(tables.def_ids[*self]).unwrap()
|
2023-10-19 17:06:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for GenericArgs {
|
|
|
|
|
type T<'tcx> = rustc_ty::GenericArgsRef<'tcx>;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.mk_args_from_iter(self.0.iter().map(|arg| arg.internal(tables, tcx)))
|
2023-10-19 17:06:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for GenericArgKind {
|
|
|
|
|
type T<'tcx> = rustc_ty::GenericArg<'tcx>;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
let arg: rustc_ty::GenericArg<'tcx> = match self {
|
|
|
|
|
GenericArgKind::Lifetime(reg) => reg.internal(tables, tcx).into(),
|
|
|
|
|
GenericArgKind::Type(ty) => ty.internal(tables, tcx).into(),
|
|
|
|
|
GenericArgKind::Const(cnst) => ty_const(cnst, tables, tcx).into(),
|
|
|
|
|
};
|
|
|
|
|
tcx.lift(arg).unwrap()
|
2023-10-19 17:06:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Region {
|
|
|
|
|
type T<'tcx> = rustc_ty::Region<'tcx>;
|
|
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
// Cannot recover region. Use erased for now.
|
|
|
|
|
tcx.lifetimes.re_erased
|
2023-10-19 17:06:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Ty {
|
|
|
|
|
type T<'tcx> = InternalTy<'tcx>;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(tables.types[*self]).unwrap()
|
2023-10-23 20:32:31 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for RigidTy {
|
|
|
|
|
type T<'tcx> = rustc_ty::TyKind<'tcx>;
|
2023-11-16 06:24:53 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-16 06:24:53 -08:00
|
|
|
match self {
|
|
|
|
|
RigidTy::Bool => rustc_ty::TyKind::Bool,
|
|
|
|
|
RigidTy::Char => rustc_ty::TyKind::Char,
|
2024-01-17 18:35:19 -08:00
|
|
|
RigidTy::Int(int_ty) => rustc_ty::TyKind::Int(int_ty.internal(tables, tcx)),
|
|
|
|
|
RigidTy::Uint(uint_ty) => rustc_ty::TyKind::Uint(uint_ty.internal(tables, tcx)),
|
|
|
|
|
RigidTy::Float(float_ty) => rustc_ty::TyKind::Float(float_ty.internal(tables, tcx)),
|
2023-11-16 06:24:53 -08:00
|
|
|
RigidTy::Never => rustc_ty::TyKind::Never,
|
|
|
|
|
RigidTy::Array(ty, cnst) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::TyKind::Array(ty.internal(tables, tcx), ty_const(cnst, tables, tcx))
|
2023-11-16 06:24:53 -08:00
|
|
|
}
|
|
|
|
|
RigidTy::Adt(def, args) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::TyKind::Adt(def.internal(tables, tcx), args.internal(tables, tcx))
|
2023-11-16 06:24:53 -08:00
|
|
|
}
|
|
|
|
|
RigidTy::Str => rustc_ty::TyKind::Str,
|
2024-01-17 18:35:19 -08:00
|
|
|
RigidTy::Slice(ty) => rustc_ty::TyKind::Slice(ty.internal(tables, tcx)),
|
2023-12-01 11:38:42 -08:00
|
|
|
RigidTy::RawPtr(ty, mutability) => rustc_ty::TyKind::RawPtr(rustc_ty::TypeAndMut {
|
2024-01-17 18:35:19 -08:00
|
|
|
ty: ty.internal(tables, tcx),
|
|
|
|
|
mutbl: mutability.internal(tables, tcx),
|
2023-12-01 11:38:42 -08:00
|
|
|
}),
|
|
|
|
|
RigidTy::Ref(region, ty, mutability) => rustc_ty::TyKind::Ref(
|
2024-01-17 18:35:19 -08:00
|
|
|
region.internal(tables, tcx),
|
|
|
|
|
ty.internal(tables, tcx),
|
|
|
|
|
mutability.internal(tables, tcx),
|
2023-12-01 11:38:42 -08:00
|
|
|
),
|
2024-01-17 18:35:19 -08:00
|
|
|
RigidTy::Foreign(def) => rustc_ty::TyKind::Foreign(def.0.internal(tables, tcx)),
|
2023-12-01 11:38:42 -08:00
|
|
|
RigidTy::FnDef(def, args) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::TyKind::FnDef(def.0.internal(tables, tcx), args.internal(tables, tcx))
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
2024-01-17 18:35:19 -08:00
|
|
|
RigidTy::FnPtr(sig) => rustc_ty::TyKind::FnPtr(sig.internal(tables, tcx)),
|
2023-12-01 11:38:42 -08:00
|
|
|
RigidTy::Closure(def, args) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::TyKind::Closure(def.0.internal(tables, tcx), args.internal(tables, tcx))
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
2023-12-25 17:04:14 +00:00
|
|
|
RigidTy::Coroutine(def, args, _mov) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::TyKind::Coroutine(def.0.internal(tables, tcx), args.internal(tables, tcx))
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
2024-01-17 18:35:19 -08:00
|
|
|
RigidTy::CoroutineWitness(def, args) => rustc_ty::TyKind::CoroutineWitness(
|
|
|
|
|
def.0.internal(tables, tcx),
|
|
|
|
|
args.internal(tables, tcx),
|
|
|
|
|
),
|
2023-12-01 11:38:42 -08:00
|
|
|
RigidTy::Dynamic(predicate, region, dyn_kind) => rustc_ty::TyKind::Dynamic(
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.mk_poly_existential_predicates(&predicate.internal(tables, tcx)),
|
|
|
|
|
region.internal(tables, tcx),
|
|
|
|
|
dyn_kind.internal(tables, tcx),
|
2023-12-01 11:38:42 -08:00
|
|
|
),
|
|
|
|
|
RigidTy::Tuple(tys) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::TyKind::Tuple(tcx.mk_type_list(&tys.internal(tables, tcx)))
|
2023-11-16 06:24:53 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for IntTy {
|
|
|
|
|
type T<'tcx> = rustc_ty::IntTy;
|
2023-11-16 06:24:53 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-16 06:24:53 -08:00
|
|
|
match self {
|
|
|
|
|
IntTy::Isize => rustc_ty::IntTy::Isize,
|
|
|
|
|
IntTy::I8 => rustc_ty::IntTy::I8,
|
|
|
|
|
IntTy::I16 => rustc_ty::IntTy::I16,
|
|
|
|
|
IntTy::I32 => rustc_ty::IntTy::I32,
|
|
|
|
|
IntTy::I64 => rustc_ty::IntTy::I64,
|
|
|
|
|
IntTy::I128 => rustc_ty::IntTy::I128,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for UintTy {
|
|
|
|
|
type T<'tcx> = rustc_ty::UintTy;
|
2023-11-16 06:24:53 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-16 06:24:53 -08:00
|
|
|
match self {
|
|
|
|
|
UintTy::Usize => rustc_ty::UintTy::Usize,
|
|
|
|
|
UintTy::U8 => rustc_ty::UintTy::U8,
|
|
|
|
|
UintTy::U16 => rustc_ty::UintTy::U16,
|
|
|
|
|
UintTy::U32 => rustc_ty::UintTy::U32,
|
|
|
|
|
UintTy::U64 => rustc_ty::UintTy::U64,
|
|
|
|
|
UintTy::U128 => rustc_ty::UintTy::U128,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for FloatTy {
|
|
|
|
|
type T<'tcx> = rustc_ty::FloatTy;
|
2023-11-16 06:24:53 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-16 06:24:53 -08:00
|
|
|
match self {
|
|
|
|
|
FloatTy::F32 => rustc_ty::FloatTy::F32,
|
|
|
|
|
FloatTy::F64 => rustc_ty::FloatTy::F64,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Mutability {
|
|
|
|
|
type T<'tcx> = rustc_ty::Mutability;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
match self {
|
|
|
|
|
Mutability::Not => rustc_ty::Mutability::Not,
|
|
|
|
|
Mutability::Mut => rustc_ty::Mutability::Mut,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Movability {
|
|
|
|
|
type T<'tcx> = rustc_ty::Movability;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
match self {
|
|
|
|
|
Movability::Static => rustc_ty::Movability::Static,
|
|
|
|
|
Movability::Movable => rustc_ty::Movability::Movable,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for FnSig {
|
|
|
|
|
type T<'tcx> = rustc_ty::FnSig<'tcx>;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(rustc_ty::FnSig {
|
2024-01-19 10:17:29 +00:00
|
|
|
inputs_and_output: tcx.mk_type_list(&self.inputs_and_output.internal(tables, tcx)),
|
2023-12-01 11:38:42 -08:00
|
|
|
c_variadic: self.c_variadic,
|
2024-01-17 18:35:19 -08:00
|
|
|
unsafety: self.unsafety.internal(tables, tcx),
|
|
|
|
|
abi: self.abi.internal(tables, tcx),
|
|
|
|
|
})
|
|
|
|
|
.unwrap()
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for VariantIdx {
|
|
|
|
|
type T<'tcx> = rustc_target::abi::VariantIdx;
|
2023-11-30 20:22:20 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-30 20:22:20 -08:00
|
|
|
rustc_target::abi::VariantIdx::from(self.to_index())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for VariantDef {
|
|
|
|
|
type T<'tcx> = &'tcx rustc_ty::VariantDef;
|
2023-11-30 20:22:20 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
self.adt_def.internal(tables, tcx).variant(self.idx.internal(tables, tcx))
|
2023-11-30 20:22:20 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-17 18:35:19 -08:00
|
|
|
fn ty_const<'tcx>(
|
|
|
|
|
constant: &Const,
|
2024-01-19 10:17:29 +00:00
|
|
|
tables: &mut Tables<'_>,
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
|
) -> rustc_ty::Const<'tcx> {
|
|
|
|
|
match constant.internal(tables, tcx) {
|
2023-10-23 20:32:31 -07:00
|
|
|
rustc_middle::mir::Const::Ty(c) => c,
|
|
|
|
|
cnst => {
|
2023-11-09 16:10:37 +09:00
|
|
|
panic!("Trying to convert constant `{constant:?}` to type constant, but found {cnst:?}")
|
2023-10-19 17:06:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Const {
|
|
|
|
|
type T<'tcx> = rustc_middle::mir::Const<'tcx>;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
let constant = tables.constants[self.id];
|
|
|
|
|
match constant {
|
|
|
|
|
rustc_middle::mir::Const::Ty(ty) => rustc_middle::mir::Const::Ty(tcx.lift(ty).unwrap()),
|
|
|
|
|
rustc_middle::mir::Const::Unevaluated(uneval, ty) => {
|
|
|
|
|
rustc_middle::mir::Const::Unevaluated(
|
2024-01-19 10:17:29 +00:00
|
|
|
tcx.lift(uneval).unwrap(),
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(ty).unwrap(),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
rustc_middle::mir::Const::Val(const_val, ty) => {
|
|
|
|
|
rustc_middle::mir::Const::Val(tcx.lift(const_val).unwrap(), tcx.lift(ty).unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-19 17:06:53 -07:00
|
|
|
}
|
|
|
|
|
}
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for MonoItem {
|
|
|
|
|
type T<'tcx> = rustc_middle::mir::mono::MonoItem<'tcx>;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-07 14:07:32 -08:00
|
|
|
use rustc_middle::mir::mono as rustc_mono;
|
|
|
|
|
match self {
|
2024-01-17 18:35:19 -08:00
|
|
|
MonoItem::Fn(instance) => rustc_mono::MonoItem::Fn(instance.internal(tables, tcx)),
|
|
|
|
|
MonoItem::Static(def) => rustc_mono::MonoItem::Static(def.internal(tables, tcx)),
|
2023-11-07 14:07:32 -08:00
|
|
|
MonoItem::GlobalAsm(_) => {
|
|
|
|
|
unimplemented!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Instance {
|
|
|
|
|
type T<'tcx> = rustc_ty::Instance<'tcx>;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(tables.instances[self.def]).unwrap()
|
2023-11-07 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for StaticDef {
|
|
|
|
|
type T<'tcx> = rustc_span::def_id::DefId;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
self.0.internal(tables, tcx)
|
2023-11-07 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[allow(rustc::usage_of_qualified_ty)]
|
2024-01-19 10:17:29 +00:00
|
|
|
impl<T> RustcInternal for Binder<T>
|
2023-11-07 14:07:32 -08:00
|
|
|
where
|
2024-01-19 10:17:29 +00:00
|
|
|
T: RustcInternal,
|
|
|
|
|
for<'tcx> T::T<'tcx>: rustc_ty::TypeVisitable<rustc_ty::TyCtxt<'tcx>>,
|
2023-11-07 14:07:32 -08:00
|
|
|
{
|
2024-01-19 10:17:29 +00:00
|
|
|
type T<'tcx> = rustc_ty::Binder<'tcx, T::T<'tcx>>;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-07 14:07:32 -08:00
|
|
|
rustc_ty::Binder::bind_with_vars(
|
2024-01-17 18:35:19 -08:00
|
|
|
self.value.internal(tables, tcx),
|
|
|
|
|
tcx.mk_bound_variable_kinds_from_iter(
|
|
|
|
|
self.bound_vars.iter().map(|bound| bound.internal(tables, tcx)),
|
2023-11-07 14:07:32 -08:00
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for BoundVariableKind {
|
|
|
|
|
type T<'tcx> = rustc_ty::BoundVariableKind;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-07 14:07:32 -08:00
|
|
|
match self {
|
|
|
|
|
BoundVariableKind::Ty(kind) => rustc_ty::BoundVariableKind::Ty(match kind {
|
|
|
|
|
BoundTyKind::Anon => rustc_ty::BoundTyKind::Anon,
|
2024-01-17 18:35:19 -08:00
|
|
|
BoundTyKind::Param(def, symbol) => rustc_ty::BoundTyKind::Param(
|
|
|
|
|
def.0.internal(tables, tcx),
|
|
|
|
|
Symbol::intern(symbol),
|
|
|
|
|
),
|
2023-11-07 14:07:32 -08:00
|
|
|
}),
|
|
|
|
|
BoundVariableKind::Region(kind) => rustc_ty::BoundVariableKind::Region(match kind {
|
|
|
|
|
BoundRegionKind::BrAnon => rustc_ty::BoundRegionKind::BrAnon,
|
|
|
|
|
BoundRegionKind::BrNamed(def, symbol) => rustc_ty::BoundRegionKind::BrNamed(
|
2024-01-17 18:35:19 -08:00
|
|
|
def.0.internal(tables, tcx),
|
2023-11-21 20:07:32 +01:00
|
|
|
Symbol::intern(symbol),
|
2023-11-07 14:07:32 -08:00
|
|
|
),
|
|
|
|
|
BoundRegionKind::BrEnv => rustc_ty::BoundRegionKind::BrEnv,
|
|
|
|
|
}),
|
|
|
|
|
BoundVariableKind::Const => rustc_ty::BoundVariableKind::Const,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for DynKind {
|
|
|
|
|
type T<'tcx> = rustc_ty::DynKind;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
match self {
|
|
|
|
|
DynKind::Dyn => rustc_ty::DynKind::Dyn,
|
|
|
|
|
DynKind::DynStar => rustc_ty::DynKind::DynStar,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for ExistentialPredicate {
|
|
|
|
|
type T<'tcx> = rustc_ty::ExistentialPredicate<'tcx>;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
match self {
|
|
|
|
|
ExistentialPredicate::Trait(trait_ref) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::ExistentialPredicate::Trait(trait_ref.internal(tables, tcx))
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
|
|
|
|
ExistentialPredicate::Projection(proj) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::ExistentialPredicate::Projection(proj.internal(tables, tcx))
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
|
|
|
|
ExistentialPredicate::AutoTrait(trait_def) => {
|
2024-01-17 18:35:19 -08:00
|
|
|
rustc_ty::ExistentialPredicate::AutoTrait(trait_def.0.internal(tables, tcx))
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for ExistentialProjection {
|
|
|
|
|
type T<'tcx> = rustc_ty::ExistentialProjection<'tcx>;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
rustc_ty::ExistentialProjection {
|
2024-01-17 18:35:19 -08:00
|
|
|
def_id: self.def_id.0.internal(tables, tcx),
|
|
|
|
|
args: self.generic_args.internal(tables, tcx),
|
|
|
|
|
term: self.term.internal(tables, tcx),
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for TermKind {
|
|
|
|
|
type T<'tcx> = rustc_ty::Term<'tcx>;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
match self {
|
2024-01-17 18:35:19 -08:00
|
|
|
TermKind::Type(ty) => ty.internal(tables, tcx).into(),
|
|
|
|
|
TermKind::Const(const_) => ty_const(const_, tables, tcx).into(),
|
2023-12-01 11:38:42 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for ExistentialTraitRef {
|
|
|
|
|
type T<'tcx> = rustc_ty::ExistentialTraitRef<'tcx>;
|
2023-11-17 08:05:40 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-17 08:05:40 -08:00
|
|
|
rustc_ty::ExistentialTraitRef {
|
2024-01-17 18:35:19 -08:00
|
|
|
def_id: self.def_id.0.internal(tables, tcx),
|
|
|
|
|
args: self.generic_args.internal(tables, tcx),
|
2023-11-17 08:05:40 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for TraitRef {
|
|
|
|
|
type T<'tcx> = rustc_ty::TraitRef<'tcx>;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-07 14:07:32 -08:00
|
|
|
rustc_ty::TraitRef::new(
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx,
|
|
|
|
|
self.def_id.0.internal(tables, tcx),
|
|
|
|
|
self.args().internal(tables, tcx),
|
2023-11-07 14:07:32 -08:00
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for AllocId {
|
|
|
|
|
type T<'tcx> = rustc_middle::mir::interpret::AllocId;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(tables.alloc_ids[*self]).unwrap()
|
2023-11-07 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for ClosureKind {
|
|
|
|
|
type T<'tcx> = rustc_ty::ClosureKind;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-07 14:07:32 -08:00
|
|
|
match self {
|
|
|
|
|
ClosureKind::Fn => rustc_ty::ClosureKind::Fn,
|
|
|
|
|
ClosureKind::FnMut => rustc_ty::ClosureKind::FnMut,
|
|
|
|
|
ClosureKind::FnOnce => rustc_ty::ClosureKind::FnOnce,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for AdtDef {
|
|
|
|
|
type T<'tcx> = rustc_ty::AdtDef<'tcx>;
|
|
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.adt_def(self.0.internal(tables, tcx))
|
2023-11-16 06:24:53 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Abi {
|
|
|
|
|
type T<'tcx> = rustc_target::spec::abi::Abi;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
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::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::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,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Safety {
|
|
|
|
|
type T<'tcx> = rustc_hir::Unsafety;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, _tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-12-01 11:38:42 -08:00
|
|
|
match self {
|
|
|
|
|
Safety::Unsafe => rustc_hir::Unsafety::Unsafe,
|
|
|
|
|
Safety::Normal => rustc_hir::Unsafety::Normal,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Span {
|
|
|
|
|
type T<'tcx> = rustc_span::Span;
|
2023-11-21 19:09:01 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, _tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2023-11-21 19:09:01 -08:00
|
|
|
tables[*self]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl RustcInternal for Layout {
|
|
|
|
|
type T<'tcx> = rustc_target::abi::Layout<'tcx>;
|
2023-12-18 19:52:25 +00:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
tcx.lift(tables.layouts[*self]).unwrap()
|
2023-12-18 19:52:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl<T> RustcInternal for &T
|
2023-11-07 14:07:32 -08:00
|
|
|
where
|
2024-01-19 10:17:29 +00:00
|
|
|
T: RustcInternal,
|
2023-11-07 14:07:32 -08:00
|
|
|
{
|
2024-01-19 10:17:29 +00:00
|
|
|
type T<'tcx> = T::T<'tcx>;
|
2023-11-07 14:07:32 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
(*self).internal(tables, tcx)
|
2023-11-07 14:07:32 -08:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl<T> RustcInternal for Option<T>
|
2023-11-17 08:05:40 -08:00
|
|
|
where
|
2024-01-19 10:17:29 +00:00
|
|
|
T: RustcInternal,
|
2023-11-17 08:05:40 -08:00
|
|
|
{
|
2024-01-19 10:17:29 +00:00
|
|
|
type T<'tcx> = Option<T::T<'tcx>>;
|
2023-11-17 08:05:40 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
self.as_ref().map(|inner| inner.internal(tables, tcx))
|
2023-11-17 08:05:40 -08:00
|
|
|
}
|
|
|
|
|
}
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
impl<T> RustcInternal for Vec<T>
|
2023-12-01 11:38:42 -08:00
|
|
|
where
|
2024-01-19 10:17:29 +00:00
|
|
|
T: RustcInternal,
|
2023-12-01 11:38:42 -08:00
|
|
|
{
|
2024-01-19 10:17:29 +00:00
|
|
|
type T<'tcx> = Vec<T::T<'tcx>>;
|
2023-12-01 11:38:42 -08:00
|
|
|
|
2024-01-19 10:17:29 +00:00
|
|
|
fn internal<'tcx>(&self, tables: &mut Tables<'_>, tcx: TyCtxt<'tcx>) -> Self::T<'tcx> {
|
2024-01-17 18:35:19 -08:00
|
|
|
self.iter().map(|e| e.internal(tables, tcx)).collect()
|
|
|
|
|
}
|
|
|
|
|
}
|