Skip to content

Commit

Permalink
Auto merge of rust-lang#77041 - lcnr:const-eval-perf, r=ecstatic-morse
Browse files Browse the repository at this point in the history
perf: move cold path of `process_obligations` into a separate function

cc rust-lang#76575

This probably won't matter too much in the long run once rust-lang#69218 is merged so we may not want to merge this.

r? `@ecstatic-morse`
  • Loading branch information
bors committed Sep 25, 2020
2 parents fadf025 + 06d2325 commit 521d8d8
Showing 1 changed file with 27 additions and 18 deletions.
45 changes: 27 additions & 18 deletions compiler/rustc_trait_selection/src/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,34 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
return ProcessResult::Unchanged;
}

// This part of the code is much colder.
self.progress_changed_obligations(pending_obligation)
}

fn process_backedge<'c, I>(
&mut self,
cycle: I,
_marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
) where
I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
{
if self.selcx.coinductive_match(cycle.clone().map(|s| s.obligation.predicate)) {
debug!("process_child_obligations: coinductive match");
} else {
let cycle: Vec<_> = cycle.map(|c| c.obligation.clone()).collect();
self.selcx.infcx().report_overflow_error_cycle(&cycle);
}
}
}

impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
// The code calling this method is extremely hot and only rarely
// actually uses this, so move this part of the code
// out of that loop.
#[inline(never)]
fn progress_changed_obligations(
&mut self,
pending_obligation: &mut PendingPredicateObligation<'tcx>,
) -> ProcessResult<PendingPredicateObligation<'tcx>, FulfillmentErrorCode<'tcx>> {
pending_obligation.stalled_on.truncate(0);

let obligation = &mut pending_obligation.obligation;
Expand Down Expand Up @@ -565,23 +591,6 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
}
}

fn process_backedge<'c, I>(
&mut self,
cycle: I,
_marker: PhantomData<&'c PendingPredicateObligation<'tcx>>,
) where
I: Clone + Iterator<Item = &'c PendingPredicateObligation<'tcx>>,
{
if self.selcx.coinductive_match(cycle.clone().map(|s| s.obligation.predicate)) {
debug!("process_child_obligations: coinductive match");
} else {
let cycle: Vec<_> = cycle.map(|c| c.obligation.clone()).collect();
self.selcx.infcx().report_overflow_error_cycle(&cycle);
}
}
}

impl<'a, 'b, 'tcx> FulfillProcessor<'a, 'b, 'tcx> {
fn process_trait_obligation(
&mut self,
obligation: &PredicateObligation<'tcx>,
Expand Down

0 comments on commit 521d8d8

Please sign in to comment.