@@ -43,14 +43,16 @@ pub enum Constant<'tcx> {
4343 Char ( char ) ,
4444 /// An integer's bit representation.
4545 Int ( u128 ) ,
46- /// An `f16`.
47- F16 ( f16 ) ,
46+ /// An `f16` bitcast to a `u16`.
47+ // FIXME(f16_f128): use `f16` once builtins are available on all host tools platforms.
48+ F16 ( u16 ) ,
4849 /// An `f32`.
4950 F32 ( f32 ) ,
5051 /// An `f64`.
5152 F64 ( f64 ) ,
52- /// An `f128`.
53- F128 ( f128 ) ,
53+ /// An `f128` bitcast to a `u128`.
54+ // FIXME(f16_f128): use `f128` once builtins are available on all host tools platforms.
55+ F128 ( u128 ) ,
5456 /// `true` or `false`.
5557 Bool ( bool ) ,
5658 /// An array of constants.
@@ -177,7 +179,7 @@ impl Hash for Constant<'_> {
177179 } ,
178180 Self :: F16 ( f) => {
179181 // FIXME(f16_f128): once conversions to/from `f128` are available on all platforms,
180- f. to_bits ( ) . hash ( state) ;
182+ f. hash ( state) ;
181183 } ,
182184 Self :: F32 ( f) => {
183185 f64:: from ( f) . to_bits ( ) . hash ( state) ;
@@ -186,7 +188,7 @@ impl Hash for Constant<'_> {
186188 f. to_bits ( ) . hash ( state) ;
187189 } ,
188190 Self :: F128 ( f) => {
189- f. to_bits ( ) . hash ( state) ;
191+ f. hash ( state) ;
190192 } ,
191193 Self :: Bool ( b) => {
192194 b. hash ( state) ;
@@ -292,12 +294,12 @@ impl Constant<'_> {
292294
293295 fn parse_f16 ( s : & str ) -> Self {
294296 let f: Half = s. parse ( ) . unwrap ( ) ;
295- Self :: F16 ( f16 :: from_bits ( f. to_bits ( ) . try_into ( ) . unwrap ( ) ) )
297+ Self :: F16 ( f. to_bits ( ) . try_into ( ) . unwrap ( ) )
296298 }
297299
298300 fn parse_f128 ( s : & str ) -> Self {
299301 let f: Quad = s. parse ( ) . unwrap ( ) ;
300- Self :: F128 ( f128 :: from_bits ( f. to_bits ( ) ) )
302+ Self :: F128 ( f. to_bits ( ) )
301303 }
302304}
303305
@@ -868,10 +870,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::Const<'tcx>) -> Option
868870 ty:: Adt ( adt_def, _) if adt_def. is_struct ( ) => Some ( Constant :: Adt ( result) ) ,
869871 ty:: Bool => Some ( Constant :: Bool ( int == ScalarInt :: TRUE ) ) ,
870872 ty:: Uint ( _) | ty:: Int ( _) => Some ( Constant :: Int ( int. to_bits ( int. size ( ) ) ) ) ,
871- ty:: Float ( FloatTy :: F16 ) => Some ( Constant :: F16 ( f16 :: from_bits ( int. into ( ) ) ) ) ,
873+ ty:: Float ( FloatTy :: F16 ) => Some ( Constant :: F16 ( int. into ( ) ) ) ,
872874 ty:: Float ( FloatTy :: F32 ) => Some ( Constant :: F32 ( f32:: from_bits ( int. into ( ) ) ) ) ,
873875 ty:: Float ( FloatTy :: F64 ) => Some ( Constant :: F64 ( f64:: from_bits ( int. into ( ) ) ) ) ,
874- ty:: Float ( FloatTy :: F128 ) => Some ( Constant :: F128 ( f128 :: from_bits ( int. into ( ) ) ) ) ,
876+ ty:: Float ( FloatTy :: F128 ) => Some ( Constant :: F128 ( int. into ( ) ) ) ,
875877 ty:: RawPtr ( _, _) => Some ( Constant :: RawPtr ( int. to_bits ( int. size ( ) ) ) ) ,
876878 _ => None ,
877879 } ,
@@ -892,10 +894,10 @@ pub fn mir_to_const<'tcx>(tcx: TyCtxt<'tcx>, result: mir::Const<'tcx>) -> Option
892894 let range = alloc_range ( offset + size * idx, size) ;
893895 let val = alloc. read_scalar ( & tcx, range, /* read_provenance */ false ) . ok ( ) ?;
894896 res. push ( match flt {
895- FloatTy :: F16 => Constant :: F16 ( f16 :: from_bits ( val. to_u16 ( ) . discard_err ( ) ?) ) ,
897+ FloatTy :: F16 => Constant :: F16 ( val. to_u16 ( ) . discard_err ( ) ?) ,
896898 FloatTy :: F32 => Constant :: F32 ( f32:: from_bits ( val. to_u32 ( ) . discard_err ( ) ?) ) ,
897899 FloatTy :: F64 => Constant :: F64 ( f64:: from_bits ( val. to_u64 ( ) . discard_err ( ) ?) ) ,
898- FloatTy :: F128 => Constant :: F128 ( f128 :: from_bits ( val. to_u128 ( ) . discard_err ( ) ?) ) ,
900+ FloatTy :: F128 => Constant :: F128 ( val. to_u128 ( ) . discard_err ( ) ?) ,
899901 } ) ;
900902 }
901903 Some ( Constant :: Vec ( res) )
0 commit comments