mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Add Adt to SMIR
This commit is contained in:
parent
5cf570f325
commit
c80a0f3178
@ -27,21 +27,33 @@ pub fn crate_item(did: DefId) -> stable_mir::CrateItem {
|
|||||||
with_tables(|t| t.crate_item(did))
|
with_tables(|t| t.crate_item(did))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn adt_def(did: DefId) -> stable_mir::ty::AdtDef {
|
||||||
|
with_tables(|t| t.adt_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]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem {
|
pub fn crate_item(&mut self, did: DefId) -> stable_mir::CrateItem {
|
||||||
|
stable_mir::CrateItem(self.create_def_id(did))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn adt_def(&mut self, did: DefId) -> stable_mir::ty::AdtDef {
|
||||||
|
stable_mir::ty::AdtDef(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
|
// 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() {
|
||||||
if d == did {
|
if d == did {
|
||||||
return stable_mir::CrateItem(i);
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let id = self.def_ids.len();
|
let id = self.def_ids.len();
|
||||||
self.def_ids.push(did);
|
self.def_ids.push(did);
|
||||||
stable_mir::CrateItem(id)
|
id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
|
||||||
|
|
||||||
use crate::rustc_internal::{self, opaque};
|
use crate::rustc_internal::{self, opaque};
|
||||||
use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
|
use crate::stable_mir::ty::{AdtSubsts, FloatTy, GenericArgKind, IntTy, RigidTy, TyKind, UintTy};
|
||||||
use crate::stable_mir::{self, Context};
|
use crate::stable_mir::{self, Context};
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||||
@ -94,7 +94,25 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
ty::FloatTy::F32 => TyKind::RigidTy(RigidTy::Float(FloatTy::F32)),
|
ty::FloatTy::F32 => TyKind::RigidTy(RigidTy::Float(FloatTy::F32)),
|
||||||
ty::FloatTy::F64 => TyKind::RigidTy(RigidTy::Float(FloatTy::F64)),
|
ty::FloatTy::F64 => TyKind::RigidTy(RigidTy::Float(FloatTy::F64)),
|
||||||
},
|
},
|
||||||
ty::Adt(_, _) => todo!(),
|
ty::Adt(adt_def, substs) => TyKind::RigidTy(RigidTy::Adt(
|
||||||
|
rustc_internal::adt_def(adt_def.did()),
|
||||||
|
AdtSubsts(
|
||||||
|
substs
|
||||||
|
.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::Foreign(_) => todo!(),
|
ty::Foreign(_) => todo!(),
|
||||||
ty::Str => todo!(),
|
ty::Str => todo!(),
|
||||||
ty::Array(_, _) => todo!(),
|
ty::Array(_, _) => todo!(),
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
use super::with;
|
use super::{with, DefId};
|
||||||
|
use crate::rustc_internal::Opaque;
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct Ty(pub usize);
|
pub struct Ty(pub usize);
|
||||||
@ -9,6 +10,9 @@ impl Ty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Const = Opaque;
|
||||||
|
type Region = Opaque;
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum TyKind {
|
pub enum TyKind {
|
||||||
RigidTy(RigidTy),
|
RigidTy(RigidTy),
|
||||||
@ -21,6 +25,7 @@ pub enum RigidTy {
|
|||||||
Int(IntTy),
|
Int(IntTy),
|
||||||
Uint(UintTy),
|
Uint(UintTy),
|
||||||
Float(FloatTy),
|
Float(FloatTy),
|
||||||
|
Adt(AdtDef, AdtSubsts),
|
||||||
Tuple(Vec<Ty>),
|
Tuple(Vec<Ty>),
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,3 +54,18 @@ pub enum FloatTy {
|
|||||||
F32,
|
F32,
|
||||||
F64,
|
F64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub struct AdtDef(pub(crate) DefId);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct AdtSubsts(pub Vec<GenericArgKind>);
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum GenericArgKind {
|
||||||
|
// FIXME add proper region
|
||||||
|
Lifetime(Region),
|
||||||
|
Type(Ty),
|
||||||
|
// FIXME add proper const
|
||||||
|
Const(Const),
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user