Skip to content

Commit 16ebaf9

Browse files
committed
Polished documentation, removed not-so-useful-anymore traces, and added some doc comments in mir/transform/const_prop.rs
1 parent 05d7a60 commit 16ebaf9

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/librustc_mir/transform/const_prop.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
446446
}
447447
}
448448

449+
/// Returns the value, if any, of evaluating `c`.
449450
fn eval_constant(&mut self, c: &Constant<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
450451
// FIXME we need to revisit this for #67176
451452
if c.needs_subst() {
@@ -486,11 +487,14 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
486487
}
487488
}
488489

490+
/// Returns the value, if any, of evaluating `place`.
489491
fn eval_place(&mut self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
490492
trace!("eval_place(place={:?})", place);
491493
self.use_ecx(|this| this.ecx.eval_place_to_op(place, None))
492494
}
493495

496+
/// Returns the value, if any, of evaluating `op`. Calls upon `eval_constant`
497+
/// or `eval_place`, depending on the variant of `Operand` used.
494498
fn eval_operand(&mut self, op: &Operand<'tcx>, source_info: SourceInfo) -> Option<OpTy<'tcx>> {
495499
match *op {
496500
Operand::Constant(ref c) => self.eval_constant(c, source_info),
@@ -649,6 +653,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
649653
})
650654
}
651655

656+
/// Creates a new `Operand::Constant` from a `Scalar` value
652657
fn operand_from_scalar(&self, scalar: Scalar, ty: Ty<'tcx>, span: Span) -> Operand<'tcx> {
653658
Operand::Constant(Box::new(Constant {
654659
span,
@@ -694,6 +699,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
694699
// Found a value represented as a pair. For now only do cont-prop if type of
695700
// Rvalue is also a pair with two scalars. The more general case is more
696701
// complicated to implement so we'll do it later.
702+
// FIXME: implement the general case stated above ^.
697703
let ty = &value.layout.ty.kind;
698704
// Only do it for tuples
699705
if let ty::Tuple(substs) = ty {
@@ -730,6 +736,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
730736
}
731737
}
732738

739+
/// Returns `true` if and only if this `op` should be const-propagated into.
733740
fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
734741
let mir_opt_level = self.tcx.sess.opts.debugging_opts.mir_opt_level;
735742

@@ -771,14 +778,14 @@ enum ConstPropMode {
771778

772779
struct CanConstProp {
773780
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.
775782
found_assignment: BitSet<Local>,
776783
// Cache of locals' information
777784
local_kinds: IndexVec<Local, LocalKind>,
778785
}
779786

780787
impl CanConstProp {
781-
/// returns true if `local` can be propagated
788+
/// Returns true if `local` can be propagated
782789
fn check(body: &Body<'_>) -> IndexVec<Local, ConstPropMode> {
783790
let mut cpv = CanConstProp {
784791
can_const_prop: IndexVec::from_elem(ConstPropMode::FullConstProp, &body.local_decls),
@@ -789,8 +796,8 @@ impl CanConstProp {
789796
),
790797
};
791798
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
794801
// lint for x != y
795802
// FIXME(oli-obk): lint variables until they are used in a condition
796803
// FIXME(oli-obk): lint if return value is constant
@@ -936,7 +943,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
936943
let expected = ScalarMaybeUndef::from(Scalar::from_bool(*expected));
937944
let value_const = self.ecx.read_scalar(value).unwrap();
938945
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
940947
// doesn't use the invalid value
941948
match cond {
942949
Operand::Move(ref place) | Operand::Copy(ref place) => {
@@ -1002,7 +1009,7 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10021009
}
10031010
}
10041011
}
1005-
//none of these have Operands to const-propagate
1012+
// None of these have Operands to const-propagate
10061013
TerminatorKind::Goto { .. }
10071014
| TerminatorKind::Resume
10081015
| TerminatorKind::Abort

0 commit comments

Comments
 (0)