Add Foreign to SMIR

This commit is contained in:
Santiago Pastorino 2023-07-18 11:18:40 -03:00
parent 8d361cbd91
commit 9b32319205
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
3 changed files with 15 additions and 1 deletions

View File

@ -31,6 +31,10 @@ pub fn adt_def(did: DefId) -> stable_mir::ty::AdtDef {
with_tables(|t| t.adt_def(did))
}
pub fn foreign_def(did: DefId) -> stable_mir::ty::ForeignDef {
with_tables(|t| t.foreign_def(did))
}
impl<'tcx> Tables<'tcx> {
pub fn item_def_id(&self, item: &stable_mir::CrateItem) -> DefId {
self.def_ids[item.0]
@ -44,6 +48,10 @@ impl<'tcx> Tables<'tcx> {
stable_mir::ty::AdtDef(self.create_def_id(did))
}
pub fn foreign_def(&mut self, did: DefId) -> stable_mir::ty::ForeignDef {
stable_mir::ty::ForeignDef(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() {

View File

@ -113,7 +113,9 @@ impl<'tcx> Tables<'tcx> {
.collect(),
),
)),
ty::Foreign(_) => todo!(),
ty::Foreign(def_id) => {
TyKind::RigidTy(RigidTy::Foreign(rustc_internal::foreign_def(*def_id)))
}
ty::Str => TyKind::RigidTy(RigidTy::Str),
ty::Array(ty, constant) => {
TyKind::RigidTy(RigidTy::Array(self.intern_ty(*ty), opaque(constant)))

View File

@ -26,6 +26,7 @@ pub enum RigidTy {
Uint(UintTy),
Float(FloatTy),
Adt(AdtDef, AdtSubsts),
Foreign(ForeignDef),
Str,
Array(Ty, Const),
Slice(Ty),
@ -60,6 +61,9 @@ pub enum FloatTy {
F64,
}
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct ForeignDef(pub(crate) DefId);
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct AdtDef(pub(crate) DefId);