Skip to content

Commit e5c0b96

Browse files
committed
Add FnDef ty to SMIR
1 parent 68077d5 commit e5c0b96

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ pub fn foreign_def(did: DefId) -> stable_mir::ty::ForeignDef {
3535
with_tables(|t| t.foreign_def(did))
3636
}
3737

38+
pub fn fn_def(did: DefId) -> stable_mir::ty::FnDef {
39+
with_tables(|t| t.fn_def(did))
40+
}
41+
3842
impl<'tcx> Tables<'tcx> {
3943
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
4044
self.def_ids[item.0]
@@ -52,6 +56,10 @@ impl<'tcx> Tables<'tcx> {
5256
stable_mir::ty::ForeignDef(self.create_def_id(did))
5357
}
5458

59+
pub fn fn_def(&mut self, did: DefId) -> stable_mir::ty::FnDef {
60+
stable_mir::ty::FnDef(self.create_def_id(did))
61+
}
62+
5563
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
5664
// FIXME: this becomes inefficient when we have too many ids
5765
for (i, &d) in self.def_ids.iter().enumerate() {

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
1010
use crate::rustc_internal::{self, opaque};
11-
use crate::stable_mir::ty::{FloatTy, GenericArgs, GenericArgKind, IntTy, RigidTy, TyKind, UintTy};
11+
use crate::stable_mir::ty::{FloatTy, GenericArgKind, GenericArgs, IntTy, RigidTy, TyKind, UintTy};
1212
use crate::stable_mir::{self, Context};
1313
use rustc_middle::mir;
1414
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -127,7 +127,25 @@ impl<'tcx> Tables<'tcx> {
127127
ty::Ref(region, ty, mutbl) => {
128128
TyKind::RigidTy(RigidTy::Ref(opaque(region), self.intern_ty(*ty), mutbl.stable()))
129129
}
130-
ty::FnDef(_, _) => todo!(),
130+
ty::FnDef(def_id, generic_args) => TyKind::RigidTy(RigidTy::FnDef(
131+
rustc_internal::fn_def(*def_id),
132+
GenericArgs(
133+
generic_args
134+
.iter()
135+
.map(|arg| match arg.unpack() {
136+
ty::GenericArgKind::Lifetime(region) => {
137+
GenericArgKind::Lifetime(opaque(&region))
138+
}
139+
ty::GenericArgKind::Type(ty) => {
140+
GenericArgKind::Type(self.intern_ty(ty))
141+
}
142+
ty::GenericArgKind::Const(const_) => {
143+
GenericArgKind::Const(opaque(&const_))
144+
}
145+
})
146+
.collect(),
147+
),
148+
)),
131149
ty::FnPtr(_) => todo!(),
132150
ty::Dynamic(_, _, _) => todo!(),
133151
ty::Closure(_, _) => todo!(),

compiler/rustc_smir/src/stable_mir/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum RigidTy {
3232
Slice(Ty),
3333
RawPtr(Ty, Mutability),
3434
Ref(Region, Ty, Mutability),
35+
FnDef(FnDef, GenericArgs),
3536
Never,
3637
Tuple(Vec<Ty>),
3738
}
@@ -65,6 +66,9 @@ pub enum FloatTy {
6566
#[derive(Clone, PartialEq, Eq, Debug)]
6667
pub struct ForeignDef(pub(crate) DefId);
6768

69+
#[derive(Clone, PartialEq, Eq, Debug)]
70+
pub struct FnDef(pub(crate) DefId);
71+
6872
#[derive(Clone, PartialEq, Eq, Debug)]
6973
pub struct AdtDef(pub(crate) DefId);
7074

0 commit comments

Comments
 (0)