Skip to content

Commit

Permalink
Rollup merge of rust-lang#53513 - nnethercote:inline-shallow_resolve,…
Browse files Browse the repository at this point in the history
… r=varkor

Force-inline `shallow_resolve` at its hottest call site.

It's a ~1% win on `keccak` and `inflate`.
  • Loading branch information
kennytm committed Aug 28, 2018
2 parents 7518d9d + b73843f commit b8594d9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1116,7 +1116,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
self.resolve_type_vars_if_possible(t).to_string()
}

pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
// We have this force-inlined variant of shallow_resolve() for the one
// callsite that is extremely hot. All other callsites use the normal
// variant.
#[inline(always)]
pub fn inlined_shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
match typ.sty {
ty::Infer(ty::TyVar(v)) => {
// Not entirely obvious: if `typ` is a type variable,
Expand Down Expand Up @@ -1157,6 +1161,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
}
}

pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
self.inlined_shallow_resolve(typ)
}

pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
where T: TypeFoldable<'tcx>
{
Expand Down
3 changes: 2 additions & 1 deletion src/librustc/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
// doing more work yet
if !pending_obligation.stalled_on.is_empty() {
if pending_obligation.stalled_on.iter().all(|&ty| {
let resolved_ty = self.selcx.infcx().shallow_resolve(&ty);
// Use the force-inlined variant of shallow_resolve() because this code is hot.
let resolved_ty = self.selcx.infcx().inlined_shallow_resolve(&ty);
resolved_ty == ty // nothing changed here
}) {
debug!("process_predicate: pending obligation {:?} still stalled on {:?}",
Expand Down

0 comments on commit b8594d9

Please sign in to comment.