Try out caching the stable hash of Ty within itself
This commit is contained in:
@@ -24,6 +24,7 @@ use crate::ty::{
|
||||
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::intern::Interned;
|
||||
use rustc_data_structures::memmap::Mmap;
|
||||
@@ -58,6 +59,7 @@ use rustc_span::{Span, DUMMY_SP};
|
||||
use rustc_target::abi::{Layout, TargetDataLayout, VariantIdx};
|
||||
use rustc_target::spec::abi;
|
||||
|
||||
use rustc_type_ir::TypeFlags;
|
||||
use smallvec::SmallVec;
|
||||
use std::any::Any;
|
||||
use std::borrow::Borrow;
|
||||
@@ -140,16 +142,40 @@ impl<'tcx> CtxtInterners<'tcx> {
|
||||
/// Interns a type.
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
#[inline(never)]
|
||||
fn intern_ty(&self, kind: TyKind<'tcx>) -> Ty<'tcx> {
|
||||
fn intern_ty(
|
||||
&self,
|
||||
kind: TyKind<'tcx>,
|
||||
sess: &Session,
|
||||
resolutions: &ty::ResolverOutputs,
|
||||
) -> Ty<'tcx> {
|
||||
Ty(Interned::new_unchecked(
|
||||
self.type_
|
||||
.intern(kind, |kind| {
|
||||
let flags = super::flags::FlagComputation::for_kind(&kind);
|
||||
|
||||
let stable_hash = if flags.flags.intersects(TypeFlags::HAS_RE_INFER) {
|
||||
Fingerprint::ZERO
|
||||
} else {
|
||||
let mut hasher = StableHasher::new();
|
||||
let mut hcx = StableHashingContext::new(
|
||||
sess,
|
||||
&resolutions.definitions,
|
||||
&*resolutions.cstore,
|
||||
);
|
||||
|
||||
hcx.while_hashing_spans(false, |hcx| {
|
||||
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
|
||||
kind.hash_stable(hcx, &mut hasher);
|
||||
});
|
||||
});
|
||||
hasher.finish()
|
||||
};
|
||||
|
||||
let ty_struct = TyS {
|
||||
kind,
|
||||
flags: flags.flags,
|
||||
outer_exclusive_binder: flags.outer_exclusive_binder,
|
||||
stable_hash,
|
||||
};
|
||||
|
||||
InternedInSet(self.arena.alloc(ty_struct))
|
||||
@@ -887,8 +913,12 @@ pub enum UserType<'tcx> {
|
||||
}
|
||||
|
||||
impl<'tcx> CommonTypes<'tcx> {
|
||||
fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
|
||||
let mk = |ty| interners.intern_ty(ty);
|
||||
fn new(
|
||||
interners: &CtxtInterners<'tcx>,
|
||||
sess: &Session,
|
||||
resolutions: &ty::ResolverOutputs,
|
||||
) -> CommonTypes<'tcx> {
|
||||
let mk = |ty| interners.intern_ty(ty, sess, resolutions);
|
||||
|
||||
CommonTypes {
|
||||
unit: mk(Tuple(List::empty())),
|
||||
@@ -1162,7 +1192,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
s.fatal(&err);
|
||||
});
|
||||
let interners = CtxtInterners::new(arena);
|
||||
let common_types = CommonTypes::new(&interners);
|
||||
let common_types = CommonTypes::new(&interners, s, &resolutions);
|
||||
let common_lifetimes = CommonLifetimes::new(&interners);
|
||||
let common_consts = CommonConsts::new(&interners, &common_types);
|
||||
|
||||
@@ -2276,7 +2306,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
#[allow(rustc::usage_of_ty_tykind)]
|
||||
#[inline]
|
||||
pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> {
|
||||
self.interners.intern_ty(st)
|
||||
self.interners.intern_ty(st, self.sess, &self.gcx.untracked_resolutions)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user