Don't create a new try_load_from_disk
closure for each query
Instead, define a single function, parameterized only by the return type.
This commit is contained in:
parent
112419c9f0
commit
b164dbc271
@ -255,7 +255,7 @@ fn cache_on_disk(#tcx: TyCtxt<'tcx>, #key: &Self::Key) -> bool {
|
||||
}
|
||||
|
||||
const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
|
||||
= Some(|tcx, id| tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id));
|
||||
= Some(crate::plumbing::try_load_from_disk::<Self::Value>);
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
use rustc_data_structures::sync::AtomicU64;
|
||||
use rustc_middle::arena::Arena;
|
||||
use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex};
|
||||
use rustc_middle::dep_graph::{self, DepKindStruct};
|
||||
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
|
||||
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
@ -34,6 +34,7 @@
|
||||
mod keys;
|
||||
use keys::Key;
|
||||
|
||||
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
|
||||
pub use rustc_query_system::query::QueryConfig;
|
||||
pub(crate) use rustc_query_system::query::{QueryDescription, QueryVTable};
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
//! manage the caches, and so forth.
|
||||
|
||||
use crate::keys::Key;
|
||||
use crate::on_disk_cache::CacheDecoder;
|
||||
use crate::{on_disk_cache, Queries};
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::sync::Lock;
|
||||
@ -19,6 +20,7 @@
|
||||
QuerySideEffects, QueryStackFrame,
|
||||
};
|
||||
use rustc_query_system::Value;
|
||||
use rustc_serialize::Decodable;
|
||||
use std::any::Any;
|
||||
use std::num::NonZeroU64;
|
||||
use thin_vec::ThinVec;
|
||||
@ -253,6 +255,18 @@ macro_rules! get_provider {
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! should_ever_cache_on_disk {
|
||||
([]) => {{
|
||||
None
|
||||
}};
|
||||
([(cache) $($rest:tt)*]) => {{
|
||||
Some($crate::plumbing::try_load_from_disk::<Self::Value>)
|
||||
}};
|
||||
([$other:tt $($modifiers:tt)*]) => {
|
||||
should_ever_cache_on_disk!([$($modifiers)*])
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) fn create_query_frame<
|
||||
'tcx,
|
||||
K: Copy + Key + for<'a> HashStable<StableHashingContext<'a>>,
|
||||
@ -313,6 +327,16 @@ fn try_load_from_on_disk_cache<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn try_load_from_disk<'tcx, V>(
|
||||
tcx: QueryCtxt<'tcx>,
|
||||
id: SerializedDepNodeIndex,
|
||||
) -> Option<V>
|
||||
where
|
||||
V: for<'a> Decodable<CacheDecoder<'a, 'tcx>>,
|
||||
{
|
||||
tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id)
|
||||
}
|
||||
|
||||
fn force_from_dep_node<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool
|
||||
where
|
||||
Q: QueryDescription<QueryCtxt<'tcx>>,
|
||||
|
Loading…
Reference in New Issue
Block a user