about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2018-08-17 16:05:24 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2018-08-20 10:36:39 +1000
commitb73843f9422fb487b2d26ac2d65f79f73a4c9ae3 (patch)
tree6a606bc29aec8fce03ae8d2593cb10e208adc10d
parent3ac79c718475fd29b8be34dde667b683390c2aee (diff)
downloadrust-b73843f9422fb487b2d26ac2d65f79f73a4c9ae3.tar.gz
rust-b73843f9422fb487b2d26ac2d65f79f73a4c9ae3.zip
Force-inline `shallow_resolve` at its hottest call site.
It's a ~1% win on `keccak` and `inflate`.
-rw-r--r--src/librustc/infer/mod.rs10
-rw-r--r--src/librustc/traits/fulfill.rs3
2 files changed, 11 insertions, 2 deletions
diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs
index eed6215150f..1cdbc80ccac 100644
--- a/src/librustc/infer/mod.rs
+++ b/src/librustc/infer/mod.rs
@@ -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::TyInfer(ty::TyVar(v)) => {
                 // Not entirely obvious: if `typ` is a type variable,
@@ -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>
     {
diff --git a/src/librustc/traits/fulfill.rs b/src/librustc/traits/fulfill.rs
index 5113f3cde32..a3cc6505118 100644
--- a/src/librustc/traits/fulfill.rs
+++ b/src/librustc/traits/fulfill.rs
@@ -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 {:?}",