]> git.lizzy.rs Git - rust.git/commitdiff
Force-inline `shallow_resolve` at its hottest call site.
authorNicholas Nethercote <nnethercote@mozilla.com>
Fri, 17 Aug 2018 06:05:24 +0000 (16:05 +1000)
committerNicholas Nethercote <nnethercote@mozilla.com>
Mon, 20 Aug 2018 00:36:39 +0000 (10:36 +1000)
It's a ~1% win on `keccak` and `inflate`.

src/librustc/infer/mod.rs
src/librustc/traits/fulfill.rs

index eed6215150fdbf829eafa24d7b22fcf7d54d1e0b..1cdbc80ccacf8c09c03d42e2936b17af9b68e8c1 100644 (file)
@@ -1116,7 +1116,11 @@ pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String {
         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 @@ pub fn shallow_resolve(&self, typ: Ty<'tcx>) -> Ty<'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>
     {
index 5113f3cde32843b588faee72e8e485fd5d0e2677..a3cc650511883e65d87274e053fef877c9963a16 100644 (file)
@@ -269,7 +269,8 @@ fn process_obligation(&mut self,
         // 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 {:?}",