Skip to content

Commit b73843f

Browse files
committed
Force-inline shallow_resolve at its hottest call site.
It's a ~1% win on `keccak` and `inflate`.
1 parent 3ac79c7 commit b73843f

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/librustc/infer/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
11161116
self.resolve_type_vars_if_possible(t).to_string()
11171117
}
11181118

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

1164+
pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
1165+
self.inlined_shallow_resolve(typ)
1166+
}
1167+
11601168
pub fn resolve_type_vars_if_possible<T>(&self, value: &T) -> T
11611169
where T: TypeFoldable<'tcx>
11621170
{

src/librustc/traits/fulfill.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
269269
// doing more work yet
270270
if !pending_obligation.stalled_on.is_empty() {
271271
if pending_obligation.stalled_on.iter().all(|&ty| {
272-
let resolved_ty = self.selcx.infcx().shallow_resolve(&ty);
272+
// Use the force-inlined variant of shallow_resolve() because this code is hot.
273+
let resolved_ty = self.selcx.infcx().inlined_shallow_resolve(&ty);
273274
resolved_ty == ty // nothing changed here
274275
}) {
275276
debug!("process_predicate: pending obligation {:?} still stalled on {:?}",

0 commit comments

Comments
 (0)