]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #99028 - tmiasko:inline, r=estebank
authorbors <bors@rust-lang.org>
Sat, 9 Jul 2022 04:34:51 +0000 (04:34 +0000)
committerbors <bors@rust-lang.org>
Sat, 9 Jul 2022 04:34:51 +0000 (04:34 +0000)
Miscellaneous inlining improvements

Add `#[inline]` to a few trivial non-generic methods from a perf report
that otherwise wouldn't be candidates for inlining.

1  2 
compiler/rustc_middle/src/ty/sty.rs
compiler/rustc_middle/src/ty/util.rs
compiler/rustc_query_system/src/dep_graph/graph.rs

index 03e4319bbf1a8fa1ad1e212d80aadfbf37d3133c,8369c7e0898ead62ff3f5b4fb38c9902c13ed972..4b51daadabf341dcb7d1d6e5e34df301c9e318e5
@@@ -1315,6 -1315,7 +1315,7 @@@ pub struct Region<'tcx>(pub Interned<'t
  impl<'tcx> Deref for Region<'tcx> {
      type Target = RegionKind<'tcx>;
  
+     #[inline]
      fn deref(&self) -> &RegionKind<'tcx> {
          &self.0.0
      }
@@@ -1570,19 -1571,6 +1571,19 @@@ impl<'tcx> Region<'tcx> 
              _ => bug!("free_region_binding_scope invoked on inappropriate region: {:?}", self),
          }
      }
 +
 +    /// True for free regions other than `'static`.
 +    pub fn is_free(self) -> bool {
 +        matches!(*self, ty::ReEarlyBound(_) | ty::ReFree(_))
 +    }
 +
 +    /// True if `self` is a free region or static.
 +    pub fn is_free_or_static(self) -> bool {
 +        match *self {
 +            ty::ReStatic => true,
 +            _ => self.is_free(),
 +        }
 +    }
  }
  
  /// Type utilities
index 0e581d7f1f7edf3caf17e38cb2adae313e532900,4637b30c7178d4a96cbaa5a3a1fcf3ef97bd9546..52da6c3a8c03b12f07e11a21e5f5165ebd517bce
@@@ -142,16 -142,16 +142,16 @@@ impl<'tcx> TyCtxt<'tcx> 
      /// Creates a hash of the type `Ty` which will be the same no matter what crate
      /// context it's calculated within. This is used by the `type_id` intrinsic.
      pub fn type_id_hash(self, ty: Ty<'tcx>) -> u64 {
 -        let mut hasher = StableHasher::new();
 -        let mut hcx = self.create_stable_hashing_context();
 -
          // We want the type_id be independent of the types free regions, so we
          // erase them. The erase_regions() call will also anonymize bound
          // regions, which is desirable too.
          let ty = self.erase_regions(ty);
  
 -        hcx.while_hashing_spans(false, |hcx| ty.hash_stable(hcx, &mut hasher));
 -        hasher.finish()
 +        self.with_stable_hashing_context(|mut hcx| {
 +            let mut hasher = StableHasher::new();
 +            hcx.while_hashing_spans(false, |hcx| ty.hash_stable(hcx, &mut hasher));
 +            hasher.finish()
 +        })
      }
  
      pub fn res_generics_def_id(self, res: Res) -> Option<DefId> {
@@@ -1042,6 -1042,7 +1042,7 @@@ impl<'tcx> Ty<'tcx> 
          ty
      }
  
+     #[inline]
      pub fn outer_exclusive_binder(self) -> ty::DebruijnIndex {
          self.0.outer_exclusive_binder
      }
index 0da42fddd4c1e15e1a44f0f2d3451927d113238d,5d9a4d8ce4e9f3047badb19b4a556e7f8f4ac73a..e7026096e7b503fc7e6c17865daa1ebb1bca0bcb
@@@ -43,7 -43,6 +43,7 @@@ rustc_index::newtype_index! 
  impl DepNodeIndex {
      pub const INVALID: DepNodeIndex = DepNodeIndex::MAX;
      pub const SINGLETON_DEPENDENCYLESS_ANON_NODE: DepNodeIndex = DepNodeIndex::from_u32(0);
 +    pub const FOREVER_RED_NODE: DepNodeIndex = DepNodeIndex::from_u32(1);
  }
  
  impl std::convert::From<DepNodeIndex> for QueryInvocationId {
@@@ -60,6 -59,7 +60,7 @@@ pub enum DepNodeColor 
  }
  
  impl DepNodeColor {
+     #[inline]
      pub fn is_green(self) -> bool {
          match self {
              DepNodeColor::Red => false,
@@@ -125,8 -125,6 +126,8 @@@ impl<K: DepKind> DepGraph<K> 
              record_stats,
          );
  
 +        let colors = DepNodeColorMap::new(prev_graph_node_count);
 +
          // Instantiate a dependy-less node only once for anonymous queries.
          let _green_node_index = current.intern_new_node(
              profiler,
              smallvec![],
              Fingerprint::ZERO,
          );
 -        debug_assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
 +        assert_eq!(_green_node_index, DepNodeIndex::SINGLETON_DEPENDENCYLESS_ANON_NODE);
 +
 +        // Instantiate a dependy-less red node only once for anonymous queries.
 +        let (_red_node_index, _prev_and_index) = current.intern_node(
 +            profiler,
 +            &prev_graph,
 +            DepNode { kind: DepKind::RED, hash: Fingerprint::ZERO.into() },
 +            smallvec![],
 +            None,
 +            false,
 +        );
 +        assert_eq!(_red_node_index, DepNodeIndex::FOREVER_RED_NODE);
 +        assert!(matches!(_prev_and_index, None | Some((_, DepNodeColor::Red))));
  
          DepGraph {
              data: Some(Lrc::new(DepGraphData {
                  current,
                  processed_side_effects: Default::default(),
                  previous: prev_graph,
 -                colors: DepNodeColorMap::new(prev_graph_node_count),
 +                colors,
                  debug_loaded_from_disk: Default::default(),
              })),
              virtual_dep_node_index: Lrc::new(AtomicU32::new(0)),
  
          let dcx = cx.dep_context();
          let hashing_timer = dcx.profiler().incr_result_hashing();
 -        let current_fingerprint = hash_result.map(|f| {
 -            let mut hcx = dcx.create_stable_hashing_context();
 -            f(&mut hcx, &result)
 -        });
 +        let current_fingerprint =
 +            hash_result.map(|f| dcx.with_stable_hashing_context(|mut hcx| f(&mut hcx, &result)));
  
          let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks;
  
@@@ -984,7 -972,6 +985,7 @@@ impl<K: DepKind> CurrentDepGraph<K> 
          let nanos = duration.as_secs() * 1_000_000_000 + duration.subsec_nanos() as u64;
          let mut stable_hasher = StableHasher::new();
          nanos.hash(&mut stable_hasher);
 +        let anon_id_seed = stable_hasher.finish();
  
          #[cfg(debug_assertions)]
          let forbidden_edge = match env::var("RUST_FORBID_DEP_GRAPH_EDGE") {
                  )
              }),
              prev_index_to_index: Lock::new(IndexVec::from_elem_n(None, prev_graph_node_count)),
 -            anon_id_seed: stable_hasher.finish(),
 +            anon_id_seed,
              #[cfg(debug_assertions)]
              forbidden_edge,
              total_read_count: AtomicU64::new(0),