Implement Stable for ty::GenericArgs
This commit is contained in:
parent
cbabd00c12
commit
93bcc2ef98
1 changed files with 24 additions and 25 deletions
|
@ -8,9 +8,7 @@
|
||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use crate::rustc_internal::{self, opaque};
|
use crate::rustc_internal::{self, opaque};
|
||||||
use crate::stable_mir::ty::{
|
use crate::stable_mir::ty::{FloatTy, IntTy, Movability, RigidTy, TyKind, UintTy};
|
||||||
FloatTy, GenericArgKind, GenericArgs, IntTy, Movability, RigidTy, TyKind, UintTy,
|
|
||||||
};
|
|
||||||
use crate::stable_mir::{self, Context};
|
use crate::stable_mir::{self, Context};
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
|
@ -103,7 +101,7 @@ impl<'tcx> Tables<'tcx> {
|
||||||
},
|
},
|
||||||
ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
|
ty::Adt(adt_def, generic_args) => TyKind::RigidTy(RigidTy::Adt(
|
||||||
rustc_internal::adt_def(adt_def.did()),
|
rustc_internal::adt_def(adt_def.did()),
|
||||||
self.generic_args(generic_args),
|
generic_args.stable(self),
|
||||||
)),
|
)),
|
||||||
ty::Foreign(def_id) => {
|
ty::Foreign(def_id) => {
|
||||||
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
|
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
|
||||||
|
@ -123,17 +121,17 @@ impl<'tcx> Tables<'tcx> {
|
||||||
)),
|
)),
|
||||||
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
|
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
|
||||||
rustc_internal::fn_def(*def_id),
|
rustc_internal::fn_def(*def_id),
|
||||||
self.generic_args(generic_args),
|
generic_args.stable(self),
|
||||||
)),
|
)),
|
||||||
ty::FnPtr(_) => todo!(),
|
ty::FnPtr(_) => todo!(),
|
||||||
ty::Dynamic(_, _, _) => todo!(),
|
ty::Dynamic(_, _, _) => todo!(),
|
||||||
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
||||||
rustc_internal::closure_def(*def_id),
|
rustc_internal::closure_def(*def_id),
|
||||||
self.generic_args(generic_args),
|
generic_args.stable(self),
|
||||||
)),
|
)),
|
||||||
ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator(
|
ty::Generator(def_id, generic_args, movability) => TyKind::RigidTy(RigidTy::Generator(
|
||||||
rustc_internal::generator_def(*def_id),
|
rustc_internal::generator_def(*def_id),
|
||||||
self.generic_args(generic_args),
|
generic_args.stable(self),
|
||||||
match movability {
|
match movability {
|
||||||
hir::Movability::Static => Movability::Static,
|
hir::Movability::Static => Movability::Static,
|
||||||
hir::Movability::Movable => Movability::Movable,
|
hir::Movability::Movable => Movability::Movable,
|
||||||
|
@ -164,24 +162,6 @@ impl<'tcx> Tables<'tcx> {
|
||||||
self.types.push(ty);
|
self.types.push(ty);
|
||||||
stable_mir::ty::Ty(id)
|
stable_mir::ty::Ty(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generic_args(
|
|
||||||
&mut self,
|
|
||||||
generic_args: &ty::GenericArgs<'tcx>,
|
|
||||||
) -> stable_mir::ty::GenericArgs {
|
|
||||||
GenericArgs(
|
|
||||||
generic_args
|
|
||||||
.iter()
|
|
||||||
.map(|arg| match arg.unpack() {
|
|
||||||
ty::GenericArgKind::Lifetime(region) => {
|
|
||||||
GenericArgKind::Lifetime(opaque(®ion))
|
|
||||||
}
|
|
||||||
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(self.intern_ty(ty)),
|
|
||||||
ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
|
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Build a stable mir crate from a given crate number.
|
/// Build a stable mir crate from a given crate number.
|
||||||
|
@ -582,3 +562,22 @@ impl<'tcx> Stable<'tcx> for mir::Terminator<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> Stable<'tcx> for ty::GenericArgs<'tcx> {
|
||||||
|
type T = stable_mir::ty::GenericArgs;
|
||||||
|
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
|
||||||
|
use stable_mir::ty::{GenericArgKind, GenericArgs};
|
||||||
|
|
||||||
|
GenericArgs(
|
||||||
|
self.iter()
|
||||||
|
.map(|arg| match arg.unpack() {
|
||||||
|
ty::GenericArgKind::Lifetime(region) => {
|
||||||
|
GenericArgKind::Lifetime(opaque(®ion))
|
||||||
|
}
|
||||||
|
ty::GenericArgKind::Type(ty) => GenericArgKind::Type(tables.intern_ty(ty)),
|
||||||
|
ty::GenericArgKind::Const(const_) => GenericArgKind::Const(opaque(&const_)),
|
||||||
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue