@@ -252,11 +252,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
252252 }
253253
254254 /// Returns the value, if any, of evaluating `c`.
255- fn eval_constant (
256- & mut self ,
257- c : & ConstOperand < ' tcx > ,
258- layout : Option < TyAndLayout < ' tcx > > ,
259- ) -> Option < OpTy < ' tcx > > {
255+ fn eval_constant ( & mut self , c : & ConstOperand < ' tcx > ) -> Option < OpTy < ' tcx > > {
260256 // FIXME we need to revisit this for #67176
261257 if c. has_param ( ) {
262258 return None ;
@@ -270,16 +266,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
270266 // manually normalized.
271267 let val = self . tcx . try_normalize_erasing_regions ( self . param_env , c. const_ ) . ok ( ) ?;
272268
273- self . use_ecx ( |this| this. ecx . eval_mir_constant ( & val, Some ( c. span ) , layout ) )
269+ self . use_ecx ( |this| this. ecx . eval_mir_constant ( & val, Some ( c. span ) , None ) )
274270 }
275271
276272 /// Returns the value, if any, of evaluating `place`.
277273 #[ instrument( level = "trace" , skip( self ) , ret) ]
278- fn eval_place (
279- & mut self ,
280- place : Place < ' tcx > ,
281- layout : Option < TyAndLayout < ' tcx > > ,
282- ) -> Option < OpTy < ' tcx > > {
274+ fn eval_place ( & mut self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
283275 match self . get_const ( place) ? {
284276 Value :: Immediate ( op) => Some ( op. clone ( ) ) ,
285277 Value :: Aggregate { .. } => None ,
@@ -289,14 +281,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
289281
290282 /// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
291283 /// or `eval_place`, depending on the variant of `Operand` used.
292- fn eval_operand (
293- & mut self ,
294- op : & Operand < ' tcx > ,
295- layout : Option < TyAndLayout < ' tcx > > ,
296- ) -> Option < OpTy < ' tcx > > {
284+ fn eval_operand ( & mut self , op : & Operand < ' tcx > ) -> Option < OpTy < ' tcx > > {
297285 match * op {
298- Operand :: Constant ( ref c) => self . eval_constant ( c, layout ) ,
299- Operand :: Move ( place) | Operand :: Copy ( place) => self . eval_place ( place, layout ) ,
286+ Operand :: Constant ( ref c) => self . eval_constant ( c) ,
287+ Operand :: Move ( place) | Operand :: Copy ( place) => self . eval_place ( place) ,
300288 }
301289 }
302290
@@ -319,7 +307,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
319307 }
320308
321309 fn check_unary_op ( & mut self , op : UnOp , arg : & Operand < ' tcx > , location : Location ) -> Option < ( ) > {
322- let arg = self . eval_operand ( arg, None ) ?;
310+ let arg = self . eval_operand ( arg) ?;
323311 if let ( val, true ) = self . use_ecx ( |this| {
324312 let val = this. ecx . read_immediate ( & arg) ?;
325313 let ( _res, overflow) = this. ecx . overflowing_unary_op ( op, & val) ?;
@@ -346,12 +334,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
346334 right : & Operand < ' tcx > ,
347335 location : Location ,
348336 ) -> Option < ( ) > {
349- let r = self
350- . eval_operand ( right, None )
351- . and_then ( |r| self . use_ecx ( |this| this. ecx . read_immediate ( & r) ) ) ;
352- let l = self
353- . eval_operand ( left, None )
354- . and_then ( |l| self . use_ecx ( |this| this. ecx . read_immediate ( & l) ) ) ;
337+ let r =
338+ self . eval_operand ( right) . and_then ( |r| self . use_ecx ( |this| this. ecx . read_immediate ( & r) ) ) ;
339+ let l =
340+ self . eval_operand ( left) . and_then ( |l| self . use_ecx ( |this| this. ecx . read_immediate ( & l) ) ) ;
355341 // Check for exceeding shifts *even if* we cannot evaluate the LHS.
356342 if matches ! ( op, BinOp :: Shr | BinOp :: Shl ) {
357343 let r = r. clone ( ) ?;
@@ -481,7 +467,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
481467 cond : & Operand < ' tcx > ,
482468 location : Location ,
483469 ) -> Option < !> {
484- let value = & self . eval_operand ( cond, None ) ?;
470+ let value = & self . eval_operand ( cond) ?;
485471 trace ! ( "assertion on {:?} should be {:?}" , value, expected) ;
486472
487473 let expected = Scalar :: from_bool ( expected) ;
@@ -509,7 +495,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
509495 let mut eval_to_int = |op| {
510496 // This can be `None` if the lhs wasn't const propagated and we just
511497 // triggered the assert on the value of the rhs.
512- self . eval_operand ( op, None )
498+ self . eval_operand ( op)
513499 . and_then ( |op| self . ecx . read_immediate ( & op) . ok ( ) )
514500 . map_or ( DbgVal :: Underscore , |op| DbgVal :: Val ( op. to_const_int ( ) ) )
515501 } ;
@@ -567,19 +553,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
567553 let val: Value < ' _ > = match * rvalue {
568554 ThreadLocalRef ( _) => return None ,
569555
570- Use ( ref operand) => self . eval_operand ( operand, Some ( layout ) ) ?. into ( ) ,
556+ Use ( ref operand) => self . eval_operand ( operand) ?. into ( ) ,
571557
572- CopyForDeref ( place) => self . eval_place ( place, Some ( layout ) ) ?. into ( ) ,
558+ CopyForDeref ( place) => self . eval_place ( place) ?. into ( ) ,
573559
574560 BinaryOp ( bin_op, box ( ref left, ref right) ) => {
575- let layout =
576- rustc_const_eval:: util:: binop_left_homogeneous ( bin_op) . then_some ( layout) ;
577- let left = self . eval_operand ( left, layout) ?;
561+ let left = self . eval_operand ( left) ?;
578562 let left = self . use_ecx ( |this| this. ecx . read_immediate ( & left) ) ?;
579563
580- let layout =
581- rustc_const_eval:: util:: binop_right_homogeneous ( bin_op) . then_some ( left. layout ) ;
582- let right = self . eval_operand ( right, layout) ?;
564+ let right = self . eval_operand ( right) ?;
583565 let right = self . use_ecx ( |this| this. ecx . read_immediate ( & right) ) ?;
584566
585567 let val =
@@ -588,12 +570,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
588570 }
589571
590572 CheckedBinaryOp ( bin_op, box ( ref left, ref right) ) => {
591- let left = self . eval_operand ( left, None ) ?;
573+ let left = self . eval_operand ( left) ?;
592574 let left = self . use_ecx ( |this| this. ecx . read_immediate ( & left) ) ?;
593575
594- let layout =
595- rustc_const_eval:: util:: binop_right_homogeneous ( bin_op) . then_some ( left. layout ) ;
596- let right = self . eval_operand ( right, layout) ?;
576+ let right = self . eval_operand ( right) ?;
597577 let right = self . use_ecx ( |this| this. ecx . read_immediate ( & right) ) ?;
598578
599579 let ( val, overflowed) =
@@ -606,7 +586,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
606586 }
607587
608588 UnaryOp ( un_op, ref operand) => {
609- let operand = self . eval_operand ( operand, Some ( layout ) ) ?;
589+ let operand = self . eval_operand ( operand) ?;
610590 let val = self . use_ecx ( |this| this. ecx . read_immediate ( & operand) ) ?;
611591
612592 let val = self . use_ecx ( |this| this. ecx . wrapping_unary_op ( un_op, & val) ) ?;
@@ -616,9 +596,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
616596 Aggregate ( ref kind, ref fields) => Value :: Aggregate {
617597 fields : fields
618598 . iter ( )
619- . map ( |field| {
620- self . eval_operand ( field, None ) . map_or ( Value :: Uninit , Value :: Immediate )
621- } )
599+ . map ( |field| self . eval_operand ( field) . map_or ( Value :: Uninit , Value :: Immediate ) )
622600 . collect ( ) ,
623601 variant : match * * kind {
624602 AggregateKind :: Adt ( _, variant, _, _, _) => variant,
@@ -664,21 +642,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
664642
665643 Cast ( ref kind, ref value, to) => match kind {
666644 CastKind :: IntToInt | CastKind :: IntToFloat => {
667- let value = self . eval_operand ( value, None ) ?;
645+ let value = self . eval_operand ( value) ?;
668646 let value = self . ecx . read_immediate ( & value) . ok ( ) ?;
669647 let to = self . ecx . layout_of ( to) . ok ( ) ?;
670648 let res = self . ecx . int_to_int_or_float ( & value, to) . ok ( ) ?;
671649 res. into ( )
672650 }
673651 CastKind :: FloatToFloat | CastKind :: FloatToInt => {
674- let value = self . eval_operand ( value, None ) ?;
652+ let value = self . eval_operand ( value) ?;
675653 let value = self . ecx . read_immediate ( & value) . ok ( ) ?;
676654 let to = self . ecx . layout_of ( to) . ok ( ) ?;
677655 let res = self . ecx . float_to_float_or_int ( & value, to) . ok ( ) ?;
678656 res. into ( )
679657 }
680658 CastKind :: Transmute => {
681- let value = self . eval_operand ( value, None ) ?;
659+ let value = self . eval_operand ( value) ?;
682660 let to = self . ecx . layout_of ( to) . ok ( ) ?;
683661 // `offset` for immediates only supports scalar/scalar-pair ABIs,
684662 // so bail out if the target is not one.
@@ -754,7 +732,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
754732 fn visit_constant ( & mut self , constant : & ConstOperand < ' tcx > , location : Location ) {
755733 trace ! ( "visit_constant: {:?}" , constant) ;
756734 self . super_constant ( constant, location) ;
757- self . eval_constant ( constant, None ) ;
735+ self . eval_constant ( constant) ;
758736 }
759737
760738 fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
@@ -827,7 +805,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
827805 self . check_assertion ( * expected, msg, cond, location) ;
828806 }
829807 TerminatorKind :: SwitchInt { ref discr, ref targets } => {
830- if let Some ( ref value) = self . eval_operand ( discr, None )
808+ if let Some ( ref value) = self . eval_operand ( discr)
831809 && let Some ( value_const) = self . use_ecx ( |this| this. ecx . read_scalar ( value) )
832810 && let Ok ( constant) = value_const. try_to_int ( )
833811 && let Ok ( constant) = constant. to_bits ( constant. size ( ) )
0 commit comments