Skip to content

Commit b74ecdf

Browse files
committed
Add Foreign to SMIR
1 parent c44324a commit b74ecdf

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

compiler/rustc_smir/src/rustc_internal/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ pub fn adt_def(did: DefId) -> stable_mir::ty::AdtDef {
3131
with_tables(|t| t.adt_def(did))
3232
}
3333

34+
pub fn foreign_def(did: DefId) -> stable_mir::ty::ForeignDef {
35+
with_tables(|t| t.foreign_def(did))
36+
}
37+
3438
impl<'tcx> Tables<'tcx> {
3539
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
3640
self.def_ids[item.0]
@@ -44,6 +48,10 @@ impl<'tcx> Tables<'tcx> {
4448
stable_mir::ty::AdtDef(self.create_def_id(did))
4549
}
4650

51+
pub fn foreign_def(&mut self, did: DefId) -> stable_mir::ty::ForeignDef {
52+
stable_mir::ty::ForeignDef(self.create_def_id(did))
53+
}
54+
4755
fn create_def_id(&mut self, did: DefId) -> stable_mir::DefId {
4856
// FIXME: this becomes inefficient when we have too many ids
4957
for (i, &d) in self.def_ids.iter().enumerate() {

compiler/rustc_smir/src/rustc_smir/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ impl<'tcx> Tables<'tcx> {
113113
.collect(),
114114
),
115115
)),
116-
ty::Foreign(_) => todo!(),
116+
ty::Foreign(def_id) => {
117+
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
118+
}
117119
ty::Str => TyKind::RigidTy(RigidTy::Str),
118120
ty::Array(ty, constant) => {
119121
TyKind::RigidTy(RigidTy::Array(self.intern_ty(*ty), opaque(constant)))

compiler/rustc_smir/src/stable_mir/ty.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub enum RigidTy {
2626
Uint(UintTy),
2727
Float(FloatTy),
2828
Adt(AdtDef, AdtSubsts),
29+
Foreign(ForeignDef),
2930
Str,
3031
Array(Ty, Const),
3132
Slice(Ty),
@@ -60,6 +61,9 @@ pub enum FloatTy {
6061
F64,
6162
}
6263

64+
#[derive(Clone, PartialEq, Eq, Debug)]
65+
pub struct ForeignDef(pub(crate) DefId);
66+
6367
#[derive(Clone, PartialEq, Eq, Debug)]
6468
pub struct AdtDef(pub(crate) DefId);
6569

0 commit comments

Comments
 (0)