Skip to content

Commit 9ca51b9

Browse files
committed
Add Float ty to SMIR
1 parent 42eccff commit 9ca51b9

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+6-3
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::{IntTy, RigidTy, TyKind, UintTy};
10+
use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy};
1111
use crate::stable_mir::{self, Context};
1212
use rustc_middle::mir;
1313
use rustc_middle::ty::{self, Ty, TyCtxt};
@@ -81,14 +81,17 @@ impl<'tcx> Tables<'tcx> {
8181
ty::IntTy::I128 => TyKind::RigidTy(RigidTy::Int(IntTy::I128)),
8282
},
8383
ty::Uint(uint_ty) => match uint_ty {
84-
ty::UintTy::Usize => TyKind::RigidTy(RigidTy::Uint(stable_mir::ty::UintTy::Usize)),
84+
ty::UintTy::Usize => TyKind::RigidTy(RigidTy::Uint(UintTy::Usize)),
8585
ty::UintTy::U8 => TyKind::RigidTy(RigidTy::Uint(UintTy::U8)),
8686
ty::UintTy::U16 => TyKind::RigidTy(RigidTy::Uint(UintTy::U16)),
8787
ty::UintTy::U32 => TyKind::RigidTy(RigidTy::Uint(UintTy::U32)),
8888
ty::UintTy::U64 => TyKind::RigidTy(RigidTy::Uint(UintTy::U64)),
8989
ty::UintTy::U128 => TyKind::RigidTy(RigidTy::Uint(UintTy::U128)),
9090
},
91-
ty::Float(_) => todo!(),
91+
ty::Float(float_ty) => match float_ty {
92+
ty::FloatTy::F32 => TyKind::RigidTy(RigidTy::Float(FloatTy::F32)),
93+
ty::FloatTy::F64 => TyKind::RigidTy(RigidTy::Float(FloatTy::F64)),
94+
},
9295
ty::Adt(_, _) => todo!(),
9396
ty::Foreign(_) => todo!(),
9497
ty::Str => todo!(),

compiler/rustc_smir/src/stable_mir/ty.rs

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub enum RigidTy {
2020
Char,
2121
Int(IntTy),
2222
Uint(UintTy),
23+
Float(FloatTy),
2324
Tuple(Vec<Ty>),
2425
}
2526

@@ -42,3 +43,9 @@ pub enum UintTy {
4243
U64,
4344
U128,
4445
}
46+
47+
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
48+
pub enum FloatTy {
49+
F32,
50+
F64,
51+
}

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

+8-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(), 5);
70+
assert_eq!(body.locals.len(), 6);
7171
assert_matches!(
7272
body.locals[0].kind(),
7373
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool)
@@ -88,6 +88,12 @@ fn test_stable_mir(tcx: TyCtxt<'_>) {
8888
body.locals[4].kind(),
8989
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Uint(stable_mir::ty::UintTy::U64))
9090
);
91+
assert_matches!(
92+
body.locals[5].kind(),
93+
stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Float(
94+
stable_mir::ty::FloatTy::F64
95+
))
96+
);
9197

9298
let drop = get_item(tcx, &items, (DefKind::Fn, "drop")).unwrap();
9399
let body = drop.body();
@@ -179,7 +185,7 @@ fn generate_input(path: &str) -> std::io::Result<()> {
179185
x_64.wrapping_add(y_64)
180186
}}
181187
182-
pub fn types(b: bool, _: char, _: i32, _: u64) -> bool {{
188+
pub fn types(b: bool, _: char, _: i32, _: u64, _: f64) -> bool {{
183189
b
184190
}}
185191

0 commit comments

Comments
 (0)