@@ -446,6 +446,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
446
446
}
447
447
}
448
448
449
+ /// Returns the value, if any, of evaluating `c`.
449
450
fn eval_constant ( & mut self , c : & Constant < ' tcx > , source_info : SourceInfo ) -> Option < OpTy < ' tcx > > {
450
451
// FIXME we need to revisit this for #67176
451
452
if c. needs_subst ( ) {
@@ -486,11 +487,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
486
487
}
487
488
}
488
489
490
+ /// Returns the value, if any, of evaluating `place`.
489
491
fn eval_place ( & mut self , place : Place < ' tcx > ) -> Option < OpTy < ' tcx > > {
490
492
trace ! ( "eval_place(place={:?})" , place) ;
491
493
self . use_ecx ( |this| this. ecx . eval_place_to_op ( place, None ) )
492
494
}
493
495
496
+ /// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
497
+ /// or `eval_place`, depending on the variant of `Operand` used.
494
498
fn eval_operand ( & mut self , op : & Operand < ' tcx > , source_info : SourceInfo ) -> Option < OpTy < ' tcx > > {
495
499
match * op {
496
500
Operand :: Constant ( ref c) => self . eval_constant ( c, source_info) ,
@@ -649,6 +653,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
649
653
} )
650
654
}
651
655
656
+ /// Creates a new `Operand::Constant` from a `Scalar` value
652
657
fn operand_from_scalar ( & self , scalar : Scalar , ty : Ty < ' tcx > , span : Span ) -> Operand < ' tcx > {
653
658
Operand :: Constant ( Box :: new ( Constant {
654
659
span,
@@ -694,6 +699,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
694
699
// Found a value represented as a pair. For now only do cont-prop if type of
695
700
// Rvalue is also a pair with two scalars. The more general case is more
696
701
// complicated to implement so we'll do it later.
702
+ // FIXME: implement the general case stated above ^.
697
703
let ty = & value. layout . ty . kind ;
698
704
// Only do it for tuples
699
705
if let ty:: Tuple ( substs) = ty {
@@ -730,6 +736,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
730
736
}
731
737
}
732
738
739
+ /// Returns `true` if and only if this `op` should be const-propagated into.
733
740
fn should_const_prop ( & mut self , op : OpTy < ' tcx > ) -> bool {
734
741
let mir_opt_level = self . tcx . sess . opts . debugging_opts . mir_opt_level ;
735
742
@@ -771,14 +778,14 @@ enum ConstPropMode {
771
778
772
779
struct CanConstProp {
773
780
can_const_prop : IndexVec < Local , ConstPropMode > ,
774
- // false at the beginning, once set, there are not allowed to be any more assignments
781
+ // False at the beginning. Once set, no more assignments are allowed to that local.
775
782
found_assignment : BitSet < Local > ,
776
783
// Cache of locals' information
777
784
local_kinds : IndexVec < Local , LocalKind > ,
778
785
}
779
786
780
787
impl CanConstProp {
781
- /// returns true if `local` can be propagated
788
+ /// Returns true if `local` can be propagated
782
789
fn check ( body : & Body < ' _ > ) -> IndexVec < Local , ConstPropMode > {
783
790
let mut cpv = CanConstProp {
784
791
can_const_prop : IndexVec :: from_elem ( ConstPropMode :: FullConstProp , & body. local_decls ) ,
@@ -789,8 +796,8 @@ impl CanConstProp {
789
796
) ,
790
797
} ;
791
798
for ( local, val) in cpv. can_const_prop . iter_enumerated_mut ( ) {
792
- // cannot use args at all
793
- // cannot use locals because if x < y { y - x } else { x - y } would
799
+ // Cannot use args at all
800
+ // Cannot use locals because if x < y { y - x } else { x - y } would
794
801
// lint for x != y
795
802
// FIXME(oli-obk): lint variables until they are used in a condition
796
803
// FIXME(oli-obk): lint if return value is constant
@@ -936,7 +943,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
936
943
let expected = ScalarMaybeUndef :: from ( Scalar :: from_bool ( * expected) ) ;
937
944
let value_const = self . ecx . read_scalar ( value) . unwrap ( ) ;
938
945
if expected != value_const {
939
- // poison all places this operand references so that further code
946
+ // Poison all places this operand references so that further code
940
947
// doesn't use the invalid value
941
948
match cond {
942
949
Operand :: Move ( ref place) | Operand :: Copy ( ref place) => {
@@ -1002,7 +1009,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
1002
1009
}
1003
1010
}
1004
1011
}
1005
- //none of these have Operands to const-propagate
1012
+ // None of these have Operands to const-propagate
1006
1013
TerminatorKind :: Goto { .. }
1007
1014
| TerminatorKind :: Resume
1008
1015
| TerminatorKind :: Abort
0 commit comments