Rollup merge of #113412 - spastorino:smir-types-1, r=oli-obk
Add basic types to SMIR Still incomplete but I think this can be merged and we can keep iterating over it. r? ``@oli-obk``
This commit is contained in:
commit
39f558f8cf
@ -7,7 +7,8 @@
|
|||||||
//!
|
//!
|
||||||
//! 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::stable_mir::{self, ty::TyKind, Context};
|
use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
|
||||||
|
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};
|
||||||
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE};
|
||||||
@ -69,11 +70,28 @@ pub struct Tables<'tcx> {
|
|||||||
impl<'tcx> Tables<'tcx> {
|
impl<'tcx> Tables<'tcx> {
|
||||||
fn rustc_ty_to_ty(&mut self, ty: Ty<'tcx>) -> TyKind {
|
fn rustc_ty_to_ty(&mut self, ty: Ty<'tcx>) -> TyKind {
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Bool => TyKind::Bool,
|
ty::Bool => TyKind::RigidTy(RigidTy::Bool),
|
||||||
ty::Char => todo!(),
|
ty::Char => TyKind::RigidTy(RigidTy::Char),
|
||||||
ty::Int(_) => todo!(),
|
ty::Int(int_ty) => match int_ty {
|
||||||
ty::Uint(_) => todo!(),
|
ty::IntTy::Isize => TyKind::RigidTy(RigidTy::Int(IntTy::Isize)),
|
||||||
ty::Float(_) => todo!(),
|
ty::IntTy::I8 => TyKind::RigidTy(RigidTy::Int(IntTy::I8)),
|
||||||
|
ty::IntTy::I16 => TyKind::RigidTy(RigidTy::Int(IntTy::I16)),
|
||||||
|
ty::IntTy::I32 => TyKind::RigidTy(RigidTy::Int(IntTy::I32)),
|
||||||
|
ty::IntTy::I64 => TyKind::RigidTy(RigidTy::Int(IntTy::I64)),
|
||||||
|
ty::IntTy::I128 => TyKind::RigidTy(RigidTy::Int(IntTy::I128)),
|
||||||
|
},
|
||||||
|
ty::Uint(uint_ty) => match uint_ty {
|
||||||
|
ty::UintTy::Usize => TyKind::RigidTy(RigidTy::Uint(UintTy::Usize)),
|
||||||
|
ty::UintTy::U8 => TyKind::RigidTy(RigidTy::Uint(UintTy::U8)),
|
||||||
|
ty::UintTy::U16 => TyKind::RigidTy(RigidTy::Uint(UintTy::U16)),
|
||||||
|
ty::UintTy::U32 => TyKind::RigidTy(RigidTy::Uint(UintTy::U32)),
|
||||||
|
ty::UintTy::U64 => TyKind::RigidTy(RigidTy::Uint(UintTy::U64)),
|
||||||
|
ty::UintTy::U128 => TyKind::RigidTy(RigidTy::Uint(UintTy::U128)),
|
||||||
|
},
|
||||||
|
ty::Float(float_ty) => match float_ty {
|
||||||
|
ty::FloatTy::F32 => TyKind::RigidTy(RigidTy::Float(FloatTy::F32)),
|
||||||
|
ty::FloatTy::F64 => TyKind::RigidTy(RigidTy::Float(FloatTy::F64)),
|
||||||
|
},
|
||||||
ty::Adt(_, _) => todo!(),
|
ty::Adt(_, _) => todo!(),
|
||||||
ty::Foreign(_) => todo!(),
|
ty::Foreign(_) => todo!(),
|
||||||
ty::Str => todo!(),
|
ty::Str => todo!(),
|
||||||
@ -90,9 +108,9 @@ impl<'tcx> Tables<'tcx> {
|
|||||||
ty::GeneratorWitness(_) => todo!(),
|
ty::GeneratorWitness(_) => todo!(),
|
||||||
ty::GeneratorWitnessMIR(_, _) => todo!(),
|
ty::GeneratorWitnessMIR(_, _) => todo!(),
|
||||||
ty::Never => todo!(),
|
ty::Never => todo!(),
|
||||||
ty::Tuple(fields) => {
|
ty::Tuple(fields) => TyKind::RigidTy(RigidTy::Tuple(
|
||||||
TyKind::Tuple(fields.iter().map(|ty| self.intern_ty(ty)).collect())
|
fields.iter().map(|ty| self.intern_ty(ty)).collect(),
|
||||||
}
|
)),
|
||||||
ty::Alias(_, _) => todo!(),
|
ty::Alias(_, _) => todo!(),
|
||||||
ty::Param(_) => todo!(),
|
ty::Param(_) => todo!(),
|
||||||
ty::Bound(_, _) => todo!(),
|
ty::Bound(_, _) => todo!(),
|
||||||
|
@ -9,7 +9,43 @@ impl Ty {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
pub enum TyKind {
|
pub enum TyKind {
|
||||||
|
RigidTy(RigidTy),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub enum RigidTy {
|
||||||
Bool,
|
Bool,
|
||||||
|
Char,
|
||||||
|
Int(IntTy),
|
||||||
|
Uint(UintTy),
|
||||||
|
Float(FloatTy),
|
||||||
Tuple(Vec<Ty>),
|
Tuple(Vec<Ty>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum IntTy {
|
||||||
|
Isize,
|
||||||
|
I8,
|
||||||
|
I16,
|
||||||
|
I32,
|
||||||
|
I64,
|
||||||
|
I128,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum UintTy {
|
||||||
|
Usize,
|
||||||
|
U8,
|
||||||
|
U16,
|
||||||
|
U32,
|
||||||
|
U64,
|
||||||
|
U128,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||||
|
pub enum FloatTy {
|
||||||
|
F32,
|
||||||
|
F64,
|
||||||
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
// edition: 2021
|
// edition: 2021
|
||||||
|
|
||||||
#![feature(rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
#![feature(assert_matches)]
|
||||||
|
|
||||||
extern crate rustc_driver;
|
extern crate rustc_driver;
|
||||||
extern crate rustc_hir;
|
extern crate rustc_hir;
|
||||||
@ -21,6 +22,7 @@ use rustc_interface::{interface, Queries};
|
|||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::EarlyErrorHandler;
|
use rustc_session::EarlyErrorHandler;
|
||||||
use rustc_smir::{rustc_internal, stable_mir};
|
use rustc_smir::{rustc_internal, stable_mir};
|
||||||
|
use std::assert_matches::assert_matches;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
const CRATE_NAME: &str = "input";
|
const CRATE_NAME: &str = "input";
|
||||||
@ -65,6 +67,36 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
|
|||||||
other => panic!("{other:?}"),
|
other => panic!("{other:?}"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let types = get_item(tcx, &items, (DefKind::Fn, "types")).unwrap();
|
||||||
|
let body = types.body();
|
||||||
|
assert_eq!(body.locals.len(), 6);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[0].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
||||||
|
);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[1].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
|
||||||
|
);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[2].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
|
||||||
|
);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[3].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
|
||||||
|
);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[4].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
|
||||||
|
);
|
||||||
|
assert_matches!(
|
||||||
|
body.locals[5].kind(),
|
||||||
|
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float(
|
||||||
|
stable_mir::ty::FloatTy::F64
|
||||||
|
))
|
||||||
|
);
|
||||||
|
|
||||||
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
|
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
|
||||||
let body = drop.body();
|
let body = drop.body();
|
||||||
assert_eq!(body.blocks.len(), 2);
|
assert_eq!(body.blocks.len(), 2);
|
||||||
@ -156,6 +188,10 @@ fn generate_input(path: &str) -> std::io::Result<()> {
|
|||||||
x_64.wrapping_add(y_64)
|
x_64.wrapping_add(y_64)
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
pub fn types(b: bool, _: char, _: i32, _: u64, _: f64) -> bool {{
|
||||||
|
b
|
||||||
|
}}
|
||||||
|
|
||||||
pub fn drop(_: String) {{}}
|
pub fn drop(_: String) {{}}
|
||||||
|
|
||||||
pub fn assert(x: i32) -> i32 {{
|
pub fn assert(x: i32) -> i32 {{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user