Skip to content

Commit 6f52767

Browse files
authored
Rollup merge of rust-lang#61184 - wesleywiser:const_prop_tracing, r=oli-obk
Add additional trace statements to the const propagator This makes it easier to figure out when const propagation fails.
2 parents fdd6d0d + 9bfbbd2 commit 6f52767

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/librustc_mir/transform/const_prop.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
295295
}
296296

297297
fn eval_place(&mut self, place: &Place<'tcx>, source_info: SourceInfo) -> Option<Const<'tcx>> {
298+
trace!("eval_place(place={:?})", place);
298299
match *place {
299300
Place::Base(PlaceBase::Local(loc)) => self.places[loc].clone(),
300301
Place::Projection(ref proj) => match proj.elem {
@@ -516,6 +517,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
516517
}
517518

518519
fn replace_with_const(&self, rval: &mut Rvalue<'tcx>, value: Const<'tcx>, span: Span) {
520+
trace!("attepting to replace {:?} with {:?}", rval, value);
519521
self.ecx.validate_operand(
520522
value,
521523
vec![],
@@ -579,6 +581,10 @@ impl CanConstProp {
579581
// FIXME(oli-obk): lint variables until they are used in a condition
580582
// FIXME(oli-obk): lint if return value is constant
581583
*val = mir.local_kind(local) == LocalKind::Temp;
584+
585+
if !*val {
586+
trace!("local {:?} can't be propagated because it's not a temporary", local);
587+
}
582588
}
583589
cpv.visit_mir(mir);
584590
cpv.can_const_prop
@@ -598,6 +604,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
598604
// FIXME(oli-obk): we could be more powerful here, if the multiple writes
599605
// only occur in independent execution paths
600606
MutatingUse(MutatingUseContext::Store) => if self.found_assignment[local] {
607+
trace!("local {:?} can't be propagated because of multiple assignments", local);
601608
self.can_const_prop[local] = false;
602609
} else {
603610
self.found_assignment[local] = true
@@ -609,7 +616,10 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
609616
NonMutatingUse(NonMutatingUseContext::Projection) |
610617
MutatingUse(MutatingUseContext::Projection) |
611618
NonUse(_) => {},
612-
_ => self.can_const_prop[local] = false,
619+
_ => {
620+
trace!("local {:?} can't be propagaged because it's used: {:?}", local, context);
621+
self.can_const_prop[local] = false;
622+
},
613623
}
614624
}
615625
}

0 commit comments

Comments
 (0)