Skip to content

Commit

Permalink
Select caching strategy per query.
Browse files Browse the repository at this point in the history
The per-Key choice was not used.
  • Loading branch information
cjgillot committed Feb 19, 2021
1 parent 6e4af4a commit 3bd14c7
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 70 deletions.
69 changes: 0 additions & 69 deletions compiler/rustc_middle/src/ty/query/keys.rs
Expand Up @@ -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;
Expand All @@ -25,8 +22,6 @@ pub trait Key {
}

impl<'tcx> Key for ty::InstanceDef<'tcx> {
type CacheSelector = DefaultCacheSelector;

fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
Expand All @@ -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
}
Expand All @@ -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()
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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()
}
Expand All @@ -95,8 +80,6 @@ impl Key for LocalDefId {
}

impl Key for DefId {
type CacheSelector = DefaultCacheSelector;

fn query_crate(&self) -> CrateNum {
self.krate
}
Expand All @@ -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()
}
Expand All @@ -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
}
Expand All @@ -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()
}
Expand All @@ -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
}
Expand All @@ -150,8 +125,6 @@ impl Key for (DefId, LocalDefId) {
}

impl Key for (LocalDefId, DefId) {
type CacheSelector = DefaultCacheSelector;

fn query_crate(&self) -> CrateNum {
LOCAL_CRATE
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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()
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/query/plumbing.rs
Expand Up @@ -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
Expand Down

0 comments on commit 3bd14c7

Please sign in to comment.