Skip to content

Commit 458ead4

Browse files
committed
Add Int ty to SMIR
1 parent 73e816e commit 458ead4

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//!
88
//! For now, we are developing everything inside `rustc`, thus, we keep this module private.
99
10-
use crate::stable_mir::ty::{RigidTy, TyKind};
10+
use crate::stable_mir::ty::{IntTy, RigidTy, TyKind};
1111
use crate::stable_mir::{self, Context};
1212
use rustc_middle::mir;
1313
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -72,7 +72,14 @@ impl<'tcx> Tables<'tcx> {
7272
match ty.kind() {
7373
ty::Bool => TyKind::RigidTy(RigidTy::Bool),
7474
ty::Char => TyKind::RigidTy(RigidTy::Char),
75-
ty::Int(_) => todo!(),
75+
ty::Int(int_ty) => match int_ty {
76+
ty::IntTy::Isize => TyKind::RigidTy(RigidTy::Int(IntTy::Isize)),
77+
ty::IntTy::I8 => TyKind::RigidTy(RigidTy::Int(IntTy::I8)),
78+
ty::IntTy::I16 => TyKind::RigidTy(RigidTy::Int(IntTy::I16)),
79+
ty::IntTy::I32 => TyKind::RigidTy(RigidTy::Int(IntTy::I32)),
80+
ty::IntTy::I64 => TyKind::RigidTy(RigidTy::Int(IntTy::I64)),
81+
ty::IntTy::I128 => TyKind::RigidTy(RigidTy::Int(IntTy::I128)),
82+
},
7683
ty::Uint(_) => todo!(),
7784
ty::Float(_) => todo!(),
7885
ty::Adt(_, _) => todo!(),

compiler/rustc_smir/src/stable_mir/ty.rs

+11
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,16 @@ pub enum TyKind {
1818
pub enum RigidTy {
1919
Bool,
2020
Char,
21+
Int(IntTy),
2122
Tuple(Vec<Ty>),
2223
}
24+
25+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
26+
pub enum IntTy {
27+
Isize,
28+
I8,
29+
I16,
30+
I32,
31+
I64,
32+
I128,
33+
}

tests/ui-fulldeps/stable-mir/crate-info.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
6767

6868
let types = get_item(tcx, &items, (DefKind::Fn, "types")).unwrap();
6969
let body = types.body();
70-
assert_eq!(body.locals.len(), 3);
70+
assert_eq!(body.locals.len(), 4);
7171
assert_matches!(
7272
body.locals[0].kind(),
7373
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
@@ -80,6 +80,10 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
8080
body.locals[2].kind(),
8181
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Char)
8282
);
83+
assert_matches!(
84+
body.locals[3].kind(),
85+
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Int(stable_mir::ty::IntTy::I32))
86+
);
8387

8488
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
8589
let body = drop.body();
@@ -171,7 +175,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
171175
x_64.wrapping_add(y_64)
172176
}}
173177
174-
pub fn types(b: bool, _: char) -> bool {{
178+
pub fn types(b: bool, _: char, _: i32) -> bool {{
175179
b
176180
}}
177181

0 commit comments

Comments
 (0)