Skip to content

Commit

Permalink
Revert "Add a load of debug logging around ConstProp"
Browse files Browse the repository at this point in the history
This reverts commit aef5074.
  • Loading branch information
aDotInTheVoid committed Nov 28, 2023
1 parent a95ffcf commit 6c06cf4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 34 deletions.
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -623,15 +623,13 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
///
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an
/// OpTy from a local.
#[instrument(skip(self, layout, frame))]
pub fn local_to_op(
&self,
frame: &Frame<'mir, 'tcx, M::Provenance, M::FrameExtra>,
local: mir::Local,
layout: Option<TyAndLayout<'tcx>>,
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
let layout = self.layout_of_local(frame, local, layout)?;
trace!(?frame.locals, "here's the locals");
let op = *frame.locals[local].access()?;
if matches!(op, Operand::Immediate(_)) {
if layout.is_unsized() {
Expand All @@ -640,7 +638,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
throw_inval!(ConstPropNonsense);
}
}
trace!(?op, "the op");
Ok(OpTy { op, layout })
}

Expand Down
36 changes: 5 additions & 31 deletions compiler/rustc_mir_transform/src/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
ConstPropagator { ecx, tcx, param_env, local_decls: &body.local_decls, patch }
}

#[instrument(skip(self), level = "debug")]
fn get_const(&self, place: Place<'tcx>) -> Option<OpTy<'tcx>> {
let op = match self.ecx.eval_place_to_op(place, None) {
Ok(op) => {
Expand All @@ -382,14 +381,10 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {

// Try to read the local as an immediate so that if it is representable as a scalar, we can
// handle it as such, but otherwise, just return the value as is.
let r = Some(match self.ecx.read_immediate_raw(&op) {
Some(match self.ecx.read_immediate_raw(&op) {
Ok(Right(imm)) => imm.into(),
_ => op,
});

trace!("found = {r:?}");

r
})
}

/// Remove `local` from the pool of `Locals`. Allows writing to them,
Expand All @@ -399,7 +394,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
ecx.machine.written_only_inside_own_block_locals.remove(&local);
}

#[instrument(skip(self), level = "debug")]
fn check_rvalue(&mut self, rvalue: &Rvalue<'tcx>) -> Option<()> {
// Perform any special handling for specific Rvalue types.
// Generally, checks here fall into one of two categories:
Expand Down Expand Up @@ -516,7 +510,6 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
}
}

#[instrument(skip(self), level = "debug")]
fn replace_with_const(&mut self, place: Place<'tcx>) -> Option<Const<'tcx>> {
// This will return None if the above `const_prop` invocation only "wrote" a
// type whose creation requires no write. E.g. a coroutine whose initial state
Expand Down Expand Up @@ -619,7 +612,6 @@ impl CanConstProp {
}

impl<'tcx> Visitor<'tcx> for CanConstProp {
#[instrument(skip(self), level = "debug")]
fn visit_place(&mut self, place: &Place<'tcx>, mut context: PlaceContext, loc: Location) {
use rustc_middle::mir::visit::PlaceContext::*;

Expand All @@ -632,7 +624,6 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
self.visit_projection(place.as_ref(), context, loc);
}

#[instrument(skip(self), level = "debug")]
fn visit_local(&mut self, local: Local, context: PlaceContext, _: Location) {
use rustc_middle::mir::visit::PlaceContext::*;
match context {
Expand Down Expand Up @@ -691,22 +682,15 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
}

impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
#[instrument(skip(self), level = "debug")]
fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
self.super_operand(operand, location);

trace!("about to do it");

if let Some(place) = operand.place()
&& let Some(value) = self.replace_with_const(place)
{
trace!(?place, ?value, "know whats going on");
self.patch.before_effect.insert((location, place), value);
}
}

#[instrument(skip(self), level = "debug")]

fn visit_projection_elem(
&mut self,
_: PlaceRef<'tcx>,
Expand All @@ -721,7 +705,6 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
}
}

#[instrument(skip(self), level = "debug")]
fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) {
self.super_assign(place, rvalue, location);

Expand All @@ -736,14 +719,14 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
_ if place.is_indirect() => {}
ConstPropMode::NoPropagation => self.ensure_not_propagated(place.local),
ConstPropMode::OnlyInsideOwnBlock | ConstPropMode::FullConstProp => {
trace!("trying to do some const-prop");
if let Some(()) = self.eval_rvalue_with_identities(rvalue, *place) {
// If this was already an evaluated constant, keep it.
if let Rvalue::Use(Operand::Constant(c)) = rvalue
&& let Const::Val(..) = c.const_
{
trace!(
"skipping replace of Rvalue::Use({c:?}) because it is already a const"
"skipping replace of Rvalue::Use({:?} because it is already a const",
c
);
} else if let Some(operand) = self.replace_with_const(*place) {
self.patch.assignments.insert(location, operand);
Expand All @@ -770,12 +753,8 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
}
}

#[instrument(skip(self), level = "trace")]
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
{
let frame = &self.ecx.frame().locals;
trace!(?frame, "initial frame");
}
trace!("visit_statement: {:?}", statement);

// We want to evaluate operands before any change to the assigned-to value,
// so we recurse first.
Expand Down Expand Up @@ -816,11 +795,6 @@ impl<'tcx> Visitor<'tcx> for ConstPropagator<'_, 'tcx> {
// In both cases, this does not matter, as those reads would be UB anyway.
_ => {}
}

{
let frame = &self.ecx.frame().locals;
trace!(?frame, "final frame");
}
}

fn visit_basic_block_data(&mut self, block: BasicBlock, data: &BasicBlockData<'tcx>) {
Expand Down

0 comments on commit 6c06cf4

Please sign in to comment.