Auto merge of #103808 - cjgillot:vec-cache, r=TaKO8Ki

Use an IndexVec to cache queries with index-like key

Revival of an old idea. Let's see if it has more effect.

r? `@ghost`
This commit is contained in:
bors 2022-11-24 06:32:23 +00:00
commit 341d8b8a2c
9 changed files with 232 additions and 25 deletions

View file

@ -1,4 +1,4 @@
use crate::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
use rustc_span::{def_id::DefPathHash, HashStableContext};
use std::fmt;
@ -22,6 +22,18 @@ impl OwnerId {
}
}
impl rustc_index::vec::Idx for OwnerId {
#[inline]
fn new(idx: usize) -> Self {
OwnerId { def_id: LocalDefId { local_def_index: DefIndex::from_usize(idx) } }
}
#[inline]
fn index(self) -> usize {
self.def_id.local_def_index.as_usize()
}
}
impl<CTX: HashStableContext> HashStable<CTX> for OwnerId {
#[inline]
fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) {