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))
|
||||
}
|
||||
|
||||
pub fn closure_def(did: DefId) -> stable_mir::ty::ClosureDef {
|
||||
with_tables(|t| t.closure_def(did))
|
||||
}
|
||||
|
||||
impl<'tcx> Tables<'tcx> {
|
||||
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
|
||||
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))
|
||||
}
|
||||
|
||||
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 {
|
||||
// FIXME: this becomes inefficient when we have too many ids
|
||||
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::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::Never => TyKind::RigidTy(RigidTy::Never),
|
||||
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
||||
|
@ -33,6 +33,7 @@ pub enum RigidTy {
|
||||
RawPtr(Ty, Mutability),
|
||||
Ref(Region, Ty, Mutability),
|
||||
FnDef(FnDef, GenericArgs),
|
||||
Closure(ClosureDef, GenericArgs),
|
||||
Never,
|
||||
Tuple(Vec<Ty>),
|
||||
}
|
||||
@ -69,6 +70,9 @@ pub enum FloatTy {
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct FnDef(pub(crate) DefId);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ClosureDef(pub(crate) DefId);
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub struct AdtDef(pub(crate) DefId);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user