Select caching strategy per query.

The per-Key choice was not used.
This commit is contained in:
Camille GILLOT 2020-11-18 18:45:16 +01:00
parent 6e4af4a2d1
commit 3bd14c7bbe
2 changed files with 1 additions and 70 deletions

View File

@ -6,15 +6,12 @@ use crate::ty::fast_reject::SimplifiedType;
use crate::ty::subst::{GenericArg, SubstsRef};
use crate::ty::{self, Ty, TyCtxt};
use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
use rustc_query_system::query::DefaultCacheSelector;
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 {
type CacheSelector;
/// Given an instance of this key, what crate is it referring to?
/// This is used to find the provider.
fn query_crate(&self) -> CrateNum;
@ -25,8 +22,6 @@ pub trait Key {
}
impl<'tcx> Key for ty::InstanceDef<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -37,8 +32,6 @@ impl<'tcx> Key for ty::InstanceDef<'tcx> {
}
impl<'tcx> Key for ty::Instance<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -49,8 +42,6 @@ impl<'tcx> Key for ty::Instance<'tcx> {
}
impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.instance.query_crate()
}
@ -61,8 +52,6 @@ impl<'tcx> Key for mir::interpret::GlobalId<'tcx> {
}
impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -73,8 +62,6 @@ impl<'tcx> Key for mir::interpret::LitToConstInput<'tcx> {
}
impl Key for CrateNum {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
*self
}
@ -84,8 +71,6 @@ impl Key for CrateNum {
}
impl Key for LocalDefId {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.to_def_id().query_crate()
}
@ -95,8 +80,6 @@ impl Key for LocalDefId {
}
impl Key for DefId {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.krate
}
@ -106,8 +89,6 @@ impl Key for DefId {
}
impl Key for ty::WithOptConstParam<LocalDefId> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.did.query_crate()
}
@ -117,8 +98,6 @@ impl Key for ty::WithOptConstParam<LocalDefId> {
}
impl Key for (DefId, DefId) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
@ -128,8 +107,6 @@ impl Key for (DefId, DefId) {
}
impl Key for (ty::Instance<'tcx>, LocalDefId) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.query_crate()
}
@ -139,8 +116,6 @@ impl Key for (ty::Instance<'tcx>, LocalDefId) {
}
impl Key for (DefId, LocalDefId) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
@ -150,8 +125,6 @@ impl Key for (DefId, LocalDefId) {
}
impl Key for (LocalDefId, DefId) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -161,8 +134,6 @@ impl Key for (LocalDefId, DefId) {
}
impl Key for (DefId, Option<Ident>) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
@ -172,8 +143,6 @@ impl Key for (DefId, Option<Ident>) {
}
impl Key for (DefId, LocalDefId, Ident) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
@ -183,8 +152,6 @@ impl Key for (DefId, LocalDefId, Ident) {
}
impl Key for (CrateNum, DefId) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0
}
@ -194,8 +161,6 @@ impl Key for (CrateNum, DefId) {
}
impl Key for (DefId, SimplifiedType) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
@ -205,8 +170,6 @@ impl Key for (DefId, SimplifiedType) {
}
impl<'tcx> Key for SubstsRef<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -216,8 +179,6 @@ impl<'tcx> Key for SubstsRef<'tcx> {
}
impl<'tcx> Key for (DefId, SubstsRef<'tcx>) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.0.krate
}
@ -232,8 +193,6 @@ impl<'tcx> Key
(ty::WithOptConstParam<DefId>, SubstsRef<'tcx>),
)
{
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
(self.0).0.did.krate
}
@ -243,8 +202,6 @@ impl<'tcx> Key
}
impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -254,8 +211,6 @@ impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) {
}
impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.1.def_id().krate
}
@ -265,8 +220,6 @@ impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) {
}
impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -276,8 +229,6 @@ impl<'tcx> Key for (&'tcx ty::Const<'tcx>, mir::Field) {
}
impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.def_id().krate
}
@ -287,8 +238,6 @@ impl<'tcx> Key for ty::PolyTraitRef<'tcx> {
}
impl<'tcx> Key for GenericArg<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -298,8 +247,6 @@ impl<'tcx> Key for GenericArg<'tcx> {
}
impl<'tcx> Key for &'tcx ty::Const<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -309,8 +256,6 @@ impl<'tcx> Key for &'tcx ty::Const<'tcx> {
}
impl<'tcx> Key for Ty<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -320,8 +265,6 @@ impl<'tcx> Key for Ty<'tcx> {
}
impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -331,8 +274,6 @@ impl<'tcx> Key for &'tcx ty::List<ty::Predicate<'tcx>> {
}
impl<'tcx> Key for ty::ParamEnv<'tcx> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -342,8 +283,6 @@ impl<'tcx> Key for ty::ParamEnv<'tcx> {
}
impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
self.value.query_crate()
}
@ -353,8 +292,6 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
}
impl Key for Symbol {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -366,8 +303,6 @@ impl Key for Symbol {
/// Canonical query goals correspond to abstract trait operations that
/// are not tied to any crate in particular.
impl<'tcx, T> Key for Canonical<'tcx, T> {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -378,8 +313,6 @@ impl<'tcx, T> Key for Canonical<'tcx, T> {
}
impl Key for (Symbol, u32, u32) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
@ -390,8 +323,6 @@ impl Key for (Symbol, u32, u32) {
}
impl<'tcx> Key for (DefId, Ty<'tcx>, SubstsRef<'tcx>, ty::ParamEnv<'tcx>) {
type CacheSelector = DefaultCacheSelector;
fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}

View File

@ -263,7 +263,7 @@ macro_rules! is_eval_always {
macro_rules! query_storage {
([][$K:ty, $V:ty]) => {
<<$K as Key>::CacheSelector as CacheSelector<$K, $V>>::Cache
<DefaultCacheSelector as CacheSelector<$K, $V>>::Cache
};
([storage($ty:ty) $($rest:tt)*][$K:ty, $V:ty]) => {
<$ty as CacheSelector<$K, $V>>::Cache