Skip to content

Commit

Permalink
MIR borrowck: avoid formatting state when it is not needed
Browse files Browse the repository at this point in the history
This improves performance on large functions.
  • Loading branch information
arielb1 committed Dec 5, 2017
1 parent 6bc4b50 commit 87a8a70
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/librustc_mir/borrow_check/mod.rs
Expand Up @@ -36,6 +36,7 @@ use dataflow::move_paths::{IllegalMoveOriginKind, MoveError};
use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MoveOutIndex, MovePathIndex};
use util::borrowck_errors::{BorrowckErrors, Origin};

use std::fmt;
use std::iter;

use self::MutateMode::{JustWrite, WriteAndRead};
Expand Down Expand Up @@ -308,8 +309,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
}

fn visit_block_entry(&mut self, bb: BasicBlock, flow_state: &Self::FlowState) {
let summary = flow_state.summary();
debug!("MirBorrowckCtxt::process_block({:?}): {}", bb, summary);
debug!("MirBorrowckCtxt::process_block({:?}): {}", bb, flow_state);
}

fn visit_statement_entry(
Expand All @@ -318,12 +318,11 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
stmt: &Statement<'tcx>,
flow_state: &Self::FlowState,
) {
let summary = flow_state.summary();
debug!(
"MirBorrowckCtxt::process_statement({:?}, {:?}): {}",
location,
stmt,
summary
flow_state
);
let span = stmt.source_info.span;
match stmt.kind {
Expand Down Expand Up @@ -425,12 +424,11 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
flow_state: &Self::FlowState,
) {
let loc = location;
let summary = flow_state.summary();
debug!(
"MirBorrowckCtxt::process_terminator({:?}, {:?}): {}",
location,
term,
summary
flow_state
);
let span = term.source_info.span;
match term.kind {
Expand Down Expand Up @@ -2679,8 +2677,10 @@ impl<'b, 'gcx, 'tcx> InProgress<'b, 'gcx, 'tcx> {
xform_move_outs(&mut self.move_outs);
xform_ever_inits(&mut self.ever_inits);
}
}

fn summary(&self) -> String {
impl<'b, 'gcx, 'tcx> fmt::Display for InProgress<'b, 'gcx, 'tcx> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
let mut s = String::new();

s.push_str("borrows in effect: [");
Expand Down Expand Up @@ -2757,7 +2757,7 @@ impl<'b, 'gcx, 'tcx> InProgress<'b, 'gcx, 'tcx> {
});
s.push_str("]");

return s;
fmt::Display::fmt(&s, fmt)
}
}

Expand Down

0 comments on commit 87a8a70

Please sign in to comment.