@@ -18,7 +18,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
1818 right : ImmTy < ' tcx , M :: PointerTag > ,
1919 dest : PlaceTy < ' tcx , M :: PointerTag > ,
2020 ) -> EvalResult < ' tcx > {
21- let ( val, overflowed) = self . binary_op_imm ( op, left, right) ?;
21+ let ( val, overflowed) = self . binary_op ( op, left, right) ?;
2222 let val = Immediate :: ScalarPair ( val. into ( ) , Scalar :: from_bool ( overflowed) . into ( ) ) ;
2323 self . write_immediate ( val, dest)
2424 }
@@ -32,7 +32,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
3232 right : ImmTy < ' tcx , M :: PointerTag > ,
3333 dest : PlaceTy < ' tcx , M :: PointerTag > ,
3434 ) -> EvalResult < ' tcx > {
35- let ( val, _overflowed) = self . binary_op_imm ( op, left, right) ?;
35+ let ( val, _overflowed) = self . binary_op ( op, left, right) ?;
3636 self . write_scalar ( val, dest)
3737 }
3838}
@@ -272,83 +272,70 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M>
272272 Ok ( ( val, false ) )
273273 }
274274
275- /// Convenience wrapper that's useful when keeping the layout together with the
276- /// immediate value.
275+ /// Returns the result of the specified operation and whether it overflowed.
277276 #[ inline]
278- pub fn binary_op_imm (
277+ pub fn binary_op (
279278 & self ,
280279 bin_op : mir:: BinOp ,
281280 left : ImmTy < ' tcx , M :: PointerTag > ,
282281 right : ImmTy < ' tcx , M :: PointerTag > ,
283- ) -> EvalResult < ' tcx , ( Scalar < M :: PointerTag > , bool ) > {
284- self . binary_op (
285- bin_op,
286- left. to_scalar ( ) ?, left. layout ,
287- right. to_scalar ( ) ?, right. layout ,
288- )
289- }
290-
291- /// Returns the result of the specified operation and whether it overflowed.
292- pub fn binary_op (
293- & self ,
294- bin_op : mir:: BinOp ,
295- left : Scalar < M :: PointerTag > ,
296- left_layout : TyLayout < ' tcx > ,
297- right : Scalar < M :: PointerTag > ,
298- right_layout : TyLayout < ' tcx > ,
299282 ) -> EvalResult < ' tcx , ( Scalar < M :: PointerTag > , bool ) > {
300283 trace ! ( "Running binary op {:?}: {:?} ({:?}), {:?} ({:?})" ,
301- bin_op, left, left_layout . ty, right, right_layout . ty) ;
284+ bin_op, * left, left . layout . ty, * right, right . layout . ty) ;
302285
303- match left_layout . ty . sty {
286+ match left . layout . ty . sty {
304287 ty:: Char => {
305- assert_eq ! ( left_layout . ty, right_layout . ty) ;
306- let left = left. to_char ( ) ?;
307- let right = right. to_char ( ) ?;
288+ assert_eq ! ( left . layout . ty, right . layout . ty) ;
289+ let left = left. to_scalar ( ) ? . to_char ( ) ?;
290+ let right = right. to_scalar ( ) ? . to_char ( ) ?;
308291 self . binary_char_op ( bin_op, left, right)
309292 }
310293 ty:: Bool => {
311- assert_eq ! ( left_layout . ty, right_layout . ty) ;
312- let left = left. to_bool ( ) ?;
313- let right = right. to_bool ( ) ?;
294+ assert_eq ! ( left . layout . ty, right . layout . ty) ;
295+ let left = left. to_scalar ( ) ? . to_bool ( ) ?;
296+ let right = right. to_scalar ( ) ? . to_bool ( ) ?;
314297 self . binary_bool_op ( bin_op, left, right)
315298 }
316299 ty:: Float ( fty) => {
317- assert_eq ! ( left_layout . ty, right_layout . ty) ;
318- let left = left. to_bits ( left_layout . size ) ?;
319- let right = right. to_bits ( right_layout . size ) ?;
300+ assert_eq ! ( left . layout . ty, right . layout . ty) ;
301+ let left = left. to_bits ( ) ?;
302+ let right = right. to_bits ( ) ?;
320303 self . binary_float_op ( bin_op, fty, left, right)
321304 }
322305 _ => {
323306 // Must be integer(-like) types. Don't forget about == on fn pointers.
324- assert ! ( left_layout . ty. is_integral( ) || left_layout . ty. is_unsafe_ptr( ) ||
325- left_layout . ty. is_fn( ) ) ;
326- assert ! ( right_layout . ty. is_integral( ) || right_layout . ty. is_unsafe_ptr( ) ||
327- right_layout . ty. is_fn( ) ) ;
307+ assert ! ( left . layout . ty. is_integral( ) || left . layout . ty. is_unsafe_ptr( ) ||
308+ left . layout . ty. is_fn( ) ) ;
309+ assert ! ( right . layout . ty. is_integral( ) || right . layout . ty. is_unsafe_ptr( ) ||
310+ right . layout . ty. is_fn( ) ) ;
328311
329312 // Handle operations that support pointer values
330- if left. is_ptr ( ) || right. is_ptr ( ) || bin_op == mir:: BinOp :: Offset {
331- return M :: ptr_op ( self , bin_op, left, left_layout, right, right_layout) ;
313+ if left. to_scalar_ptr ( ) ?. is_ptr ( ) ||
314+ right. to_scalar_ptr ( ) ?. is_ptr ( ) ||
315+ bin_op == mir:: BinOp :: Offset
316+ {
317+ return M :: ptr_op ( self , bin_op, left, right) ;
332318 }
333319
334320 // Everything else only works with "proper" bits
335- let left = left. to_bits ( left_layout . size ) . expect ( "we checked is_ptr" ) ;
336- let right = right. to_bits ( right_layout . size ) . expect ( "we checked is_ptr" ) ;
337- self . binary_int_op ( bin_op, left , left_layout , right , right_layout )
321+ let l = left. to_bits ( ) . expect ( "we checked is_ptr" ) ;
322+ let r = right. to_bits ( ) . expect ( "we checked is_ptr" ) ;
323+ self . binary_int_op ( bin_op, l , left . layout , r , right . layout )
338324 }
339325 }
340326 }
341327
342328 pub fn unary_op (
343329 & self ,
344330 un_op : mir:: UnOp ,
345- val : Scalar < M :: PointerTag > ,
346- layout : TyLayout < ' tcx > ,
331+ val : ImmTy < ' tcx , M :: PointerTag > ,
347332 ) -> EvalResult < ' tcx , Scalar < M :: PointerTag > > {
348333 use rustc:: mir:: UnOp :: * ;
349334 use rustc_apfloat:: ieee:: { Single , Double } ;
350335 use rustc_apfloat:: Float ;
351336
337+ let layout = val. layout ;
338+ let val = val. to_scalar ( ) ?;
352339 trace ! ( "Running unary op {:?}: {:?} ({:?})" , un_op, val, layout. ty. sty) ;
353340
354341 match layout. ty . sty {
0 commit comments