@@ -252,11 +252,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
252
252
}
253
253
254
254
/// 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 > > {
260
256
// FIXME we need to revisit this for #67176
261
257
if c. has_param ( ) {
262
258
return None ;
@@ -270,16 +266,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
270
266
// manually normalized.
271
267
let val = self . tcx . try_normalize_erasing_regions ( self . param_env , c. const_ ) . ok ( ) ?;
272
268
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 ) )
274
270
}
275
271
276
272
/// Returns the value, if any, of evaluating `place`.
277
273
#[ 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 > > {
283
275
match self . get_const ( place) ? {
284
276
Value :: Immediate ( op) => Some ( op. clone ( ) ) ,
285
277
Value :: Aggregate { .. } => None ,
@@ -289,14 +281,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
289
281
290
282
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
291
283
/// 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 > > {
297
285
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) ,
300
288
}
301
289
}
302
290
@@ -319,7 +307,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
319
307
}
320
308
321
309
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) ?;
323
311
if let ( val, true ) = self . use_ecx ( |this| {
324
312
let val = this. ecx . read_immediate ( & arg) ?;
325
313
let ( _res, overflow) = this. ecx . overflowing_unary_op ( op, & val) ?;
@@ -346,12 +334,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
346
334
right : & Operand < ' tcx > ,
347
335
location : Location ,
348
336
) -> 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) ) ) ;
355
341
// Check for exceeding shifts *even if* we cannot evaluate the LHS.
356
342
if matches ! ( op, BinOp :: Shr | BinOp :: Shl ) {
357
343
let r = r. clone ( ) ?;
@@ -481,7 +467,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
481
467
cond : & Operand < ' tcx > ,
482
468
location : Location ,
483
469
) -> Option < !> {
484
- let value = & self . eval_operand ( cond, None ) ?;
470
+ let value = & self . eval_operand ( cond) ?;
485
471
trace ! ( "assertion on {:?} should be {:?}" , value, expected) ;
486
472
487
473
let expected = Scalar :: from_bool ( expected) ;
@@ -509,7 +495,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
509
495
let mut eval_to_int = |op| {
510
496
// This can be `None` if the lhs wasn't const propagated and we just
511
497
// triggered the assert on the value of the rhs.
512
- self . eval_operand ( op, None )
498
+ self . eval_operand ( op)
513
499
. and_then ( |op| self . ecx . read_immediate ( & op) . ok ( ) )
514
500
. map_or ( DbgVal :: Underscore , |op| DbgVal :: Val ( op. to_const_int ( ) ) )
515
501
} ;
@@ -567,19 +553,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
567
553
let val: Value < ' _ > = match * rvalue {
568
554
ThreadLocalRef ( _) => return None ,
569
555
570
- Use ( ref operand) => self . eval_operand ( operand, Some ( layout ) ) ?. into ( ) ,
556
+ Use ( ref operand) => self . eval_operand ( operand) ?. into ( ) ,
571
557
572
- CopyForDeref ( place) => self . eval_place ( place, Some ( layout ) ) ?. into ( ) ,
558
+ CopyForDeref ( place) => self . eval_place ( place) ?. into ( ) ,
573
559
574
560
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) ?;
578
562
let left = self . use_ecx ( |this| this. ecx . read_immediate ( & left) ) ?;
579
563
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) ?;
583
565
let right = self . use_ecx ( |this| this. ecx . read_immediate ( & right) ) ?;
584
566
585
567
let val =
@@ -588,12 +570,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
588
570
}
589
571
590
572
CheckedBinaryOp ( bin_op, box ( ref left, ref right) ) => {
591
- let left = self . eval_operand ( left, None ) ?;
573
+ let left = self . eval_operand ( left) ?;
592
574
let left = self . use_ecx ( |this| this. ecx . read_immediate ( & left) ) ?;
593
575
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) ?;
597
577
let right = self . use_ecx ( |this| this. ecx . read_immediate ( & right) ) ?;
598
578
599
579
let ( val, overflowed) =
@@ -606,7 +586,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
606
586
}
607
587
608
588
UnaryOp ( un_op, ref operand) => {
609
- let operand = self . eval_operand ( operand, Some ( layout ) ) ?;
589
+ let operand = self . eval_operand ( operand) ?;
610
590
let val = self . use_ecx ( |this| this. ecx . read_immediate ( & operand) ) ?;
611
591
612
592
let val = self . use_ecx ( |this| this. ecx . wrapping_unary_op ( un_op, & val) ) ?;
@@ -616,9 +596,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
616
596
Aggregate ( ref kind, ref fields) => Value :: Aggregate {
617
597
fields : fields
618
598
. 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 ) )
622
600
. collect ( ) ,
623
601
variant : match * * kind {
624
602
AggregateKind :: Adt ( _, variant, _, _, _) => variant,
@@ -664,21 +642,21 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
664
642
665
643
Cast ( ref kind, ref value, to) => match kind {
666
644
CastKind :: IntToInt | CastKind :: IntToFloat => {
667
- let value = self . eval_operand ( value, None ) ?;
645
+ let value = self . eval_operand ( value) ?;
668
646
let value = self . ecx . read_immediate ( & value) . ok ( ) ?;
669
647
let to = self . ecx . layout_of ( to) . ok ( ) ?;
670
648
let res = self . ecx . int_to_int_or_float ( & value, to) . ok ( ) ?;
671
649
res. into ( )
672
650
}
673
651
CastKind :: FloatToFloat | CastKind :: FloatToInt => {
674
- let value = self . eval_operand ( value, None ) ?;
652
+ let value = self . eval_operand ( value) ?;
675
653
let value = self . ecx . read_immediate ( & value) . ok ( ) ?;
676
654
let to = self . ecx . layout_of ( to) . ok ( ) ?;
677
655
let res = self . ecx . float_to_float_or_int ( & value, to) . ok ( ) ?;
678
656
res. into ( )
679
657
}
680
658
CastKind :: Transmute => {
681
- let value = self . eval_operand ( value, None ) ?;
659
+ let value = self . eval_operand ( value) ?;
682
660
let to = self . ecx . layout_of ( to) . ok ( ) ?;
683
661
// `offset` for immediates only supports scalar/scalar-pair ABIs,
684
662
// so bail out if the target is not one.
@@ -754,7 +732,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
754
732
fn visit_constant ( & mut self , constant : & ConstOperand < ' tcx > , location : Location ) {
755
733
trace ! ( "visit_constant: {:?}" , constant) ;
756
734
self . super_constant ( constant, location) ;
757
- self . eval_constant ( constant, None ) ;
735
+ self . eval_constant ( constant) ;
758
736
}
759
737
760
738
fn visit_assign ( & mut self , place : & Place < ' tcx > , rvalue : & Rvalue < ' tcx > , location : Location ) {
@@ -827,7 +805,7 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
827
805
self . check_assertion ( * expected, msg, cond, location) ;
828
806
}
829
807
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)
831
809
&& let Some ( value_const) = self . use_ecx ( |this| this. ecx . read_scalar ( value) )
832
810
&& let Ok ( constant) = value_const. try_to_int ( )
833
811
&& let Ok ( constant) = constant. to_bits ( constant. size ( ) )
0 commit comments