Add Closure ty to SMIR
This commit is contained in:
parent
e5c0b96e24
commit
c5c38cdee8
@ -39,6 +39,10 @@ pub fn fn_def(did: DefId) -> stable_mir::ty::FnDef {
|
|||||||
with_tables(|t| t.fn_def(did))
|
with_tables(|t| t.fn_def(did))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn closure_def(did: DefId) -> stable_mir::ty::ClosureDef {
|
||||||
|
with_tables(|t| t.closure_def(did))
|
||||||
|
}
|
||||||
|
|
||||||
impl<'tcx> Tables<'tcx> {
|
impl<'tcx> Tables<'tcx> {
|
||||||
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
|
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
|
||||||
self.def_ids[item.0]
|
self.def_ids[item.0]
|
||||||
@ -60,6 +64,10 @@ pub fn fn_def(&mut self, did: DefId) -> stable_mir::ty::FnDef {
|
|||||||
stable_mir::ty::FnDef(self.create_def_id(did))
|
stable_mir::ty::FnDef(self.create_def_id(did))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn closure_def(&mut self, did: DefId) -> stable_mir::ty::ClosureDef {
|
||||||
|
stable_mir::ty::ClosureDef(self.create_def_id(did))
|
||||||
|
}
|
||||||
|
|
||||||
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
|
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
|
||||||
// FIXME: this becomes inefficient when we have too many ids
|
// FIXME: this becomes inefficient when we have too many ids
|
||||||
for (i, &d) in self.def_ids.iter().enumerate() {
|
for (i, &d) in self.def_ids.iter().enumerate() {
|
||||||
|
@ -148,7 +148,25 @@ fn rustc_ty_to_ty(&mut self, ty: Ty<'tcx>) -> TyKind {
|
|||||||
)),
|
)),
|
||||||
ty::FnPtr(_) => todo!(),
|
ty::FnPtr(_) => todo!(),
|
||||||
ty::Dynamic(_, _, _) => todo!(),
|
ty::Dynamic(_, _, _) => todo!(),
|
||||||
ty::Closure(_, _) => todo!(),
|
ty::Closure(def_id, generic_args) => TyKind::RigidTy(RigidTy::Closure(
|
||||||
|
rustc_internal::closure_def(*def_id),
|
||||||
|
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(),
|
||||||
|
),
|
||||||
|
)),
|
||||||
ty::Generator(_, _, _) => todo!(),
|
ty::Generator(_, _, _) => todo!(),
|
||||||
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
ty::Never => TyKind::RigidTy(RigidTy::Never),
|
||||||
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
||||||
|
@ -33,6 +33,7 @@ pub enum RigidTy {
|
|||||||
RawPtr(Ty, Mutability),
|
RawPtr(Ty, Mutability),
|
||||||
Ref(Region, Ty, Mutability),
|
Ref(Region, Ty, Mutability),
|
||||||
FnDef(FnDef, GenericArgs),
|
FnDef(FnDef, GenericArgs),
|
||||||
|
Closure(ClosureDef, GenericArgs),
|
||||||
Never,
|
Never,
|
||||||
Tuple(Vec<Ty>),
|
Tuple(Vec<Ty>),
|
||||||
}
|
}
|
||||||
@ -69,6 +70,9 @@ pub enum FloatTy {
|
|||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct FnDef(pub(crate) DefId);
|
pub struct FnDef(pub(crate) DefId);
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub struct ClosureDef(pub(crate) DefId);
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
pub struct AdtDef(pub(crate) DefId);
|
pub struct AdtDef(pub(crate) DefId);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user