Use Key impl to select cache.

This commit is contained in:
Camille GILLOT
2022-10-31 23:16:24 +00:00
parent ade5cffc2b
commit bc9a202a22
4 changed files with 47 additions and 13 deletions

View File

@@ -8,12 +8,15 @@ use crate::ty::subst::{GenericArg, SubstsRef};
use crate::ty::{self, layout::TyAndLayout, Ty, TyCtxt};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_hir::hir_id::{HirId, OwnerId};
use rustc_query_system::query::{DefaultCacheSelector, VecCacheSelector};
use rustc_span::symbol::{Ident, Symbol};
use rustc_span::{Span, DUMMY_SP};
/// The `Key` trait controls what types can legally be used as the key
/// for a query.
pub trait Key {
pub trait Key: Sized {
type CacheSelector = DefaultCacheSelector<Self>;
/// Given an instance of this key, what crate is it referring to?
/// This is used to find the provider.
fn query_crate_is_local(&self) -> bool;
@@ -100,6 +103,8 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
}
impl Key for CrateNum {
type CacheSelector = VecCacheSelector<Self>;
#[inline(always)]
fn query_crate_is_local(&self) -> bool {
*self == LOCAL_CRATE
@@ -110,6 +115,8 @@ impl Key for CrateNum {
}
impl Key for OwnerId {
type CacheSelector = VecCacheSelector<Self>;
#[inline(always)]
fn query_crate_is_local(&self) -> bool {
true
@@ -123,6 +130,8 @@ impl Key for OwnerId {
}
impl Key for LocalDefId {
type CacheSelector = VecCacheSelector<Self>;
#[inline(always)]
fn query_crate_is_local(&self) -> bool {
true