diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index adce55d639f..85d5bb00c4e 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -7,7 +7,7 @@ //! //! For now, we are developing everything inside `rustc`, thus, we keep this module private. -use crate::stable_mir::ty::{IntTy, RigidTy, TyKind, UintTy}; +use crate::stable_mir::ty::{FloatTy, IntTy, RigidTy, TyKind, UintTy}; use crate::stable_mir::{self, Context}; use rustc_middle::mir; use rustc_middle::ty::{self, Ty, TyCtxt}; @@ -81,14 +81,17 @@ impl<'tcx> Tables<'tcx> { ty::IntTy::I128 => TyKind::RigidTy(RigidTy::Int(IntTy::I128)), }, ty::Uint(uint_ty) => match uint_ty { - ty::UintTy::Usize => TyKind::RigidTy(RigidTy::Uint(stable_mir::ty::UintTy::Usize)), + 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(_) => todo!(), + 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::Foreign(_) => todo!(), ty::Str => todo!(), diff --git a/compiler/rustc_smir/src/stable_mir/ty.rs b/compiler/rustc_smir/src/stable_mir/ty.rs index 2db3bdb7af1..3181af46e9c 100644 --- a/compiler/rustc_smir/src/stable_mir/ty.rs +++ b/compiler/rustc_smir/src/stable_mir/ty.rs @@ -20,6 +20,7 @@ pub enum RigidTy { Char, Int(IntTy), Uint(UintTy), + Float(FloatTy), Tuple(Vec), } @@ -42,3 +43,9 @@ pub enum UintTy { U64, U128, } + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum FloatTy { + F32, + F64, +} diff --git a/tests/ui-fulldeps/stable-mir/crate-info.rs b/tests/ui-fulldeps/stable-mir/crate-info.rs index 29cc6e78d88..3c0d684a4d7 100644 --- a/tests/ui-fulldeps/stable-mir/crate-info.rs +++ b/tests/ui-fulldeps/stable-mir/crate-info.rs @@ -67,7 +67,7 @@ fn test_stable_mir(tcx: TyCtxt<'_>) { let types = get_item(tcx, &items, (DefKind::Fn, "types")).unwrap(); let body = types.body(); - assert_eq!(body.locals.len(), 5); + assert_eq!(body.locals.len(), 6); assert_matches!( body.locals[0].kind(), stable_mir::ty::TyKind::RigidTy(stable_mir::ty::RigidTy::Bool) @@ -88,6 +88,12 @@ fn test_stable_mir(tcx: TyCtxt<'_>) { 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 body = drop.body(); @@ -179,7 +185,7 @@ fn generate_input(path: &str) -> std::io::Result<()> { x_64.wrapping_add(y_64) }} - pub fn types(b: bool, _: char, _: i32, _: u64) -> bool {{ + pub fn types(b: bool, _: char, _: i32, _: u64, _: f64) -> bool {{ b }}