Skip to content

Commit b164dbc

Browse files
committed
Don't create a new try_load_from_disk closure for each query
Instead, define a single function, parameterized only by the return type.
1 parent 112419c commit b164dbc

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

compiler/rustc_macros/src/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ fn add_query_description_impl(query: &Query, impls: &mut proc_macro2::TokenStrea
255255
}
256256

257257
const TRY_LOAD_FROM_DISK: Option<fn(QueryCtxt<'tcx>, SerializedDepNodeIndex) -> Option<Self::Value>>
258-
= Some(|tcx, id| tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id));
258+
= Some(crate::plumbing::try_load_from_disk::<Self::Value>);
259259
}
260260
} else {
261261
quote! {

compiler/rustc_query_impl/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ extern crate rustc_middle;
1717

1818
use rustc_data_structures::sync::AtomicU64;
1919
use rustc_middle::arena::Arena;
20-
use rustc_middle::dep_graph::{self, DepKindStruct, SerializedDepNodeIndex};
20+
use rustc_middle::dep_graph::{self, DepKindStruct};
2121
use rustc_middle::ty::query::{query_keys, query_storage, query_stored, query_values};
2222
use rustc_middle::ty::query::{ExternProviders, Providers, QueryEngine};
2323
use rustc_middle::ty::{self, TyCtxt};
@@ -34,6 +34,7 @@ pub use rustc_query_system::query::{deadlock, QueryContext};
3434
mod keys;
3535
use keys::Key;
3636

37+
use rustc_query_system::dep_graph::SerializedDepNodeIndex;
3738
pub use rustc_query_system::query::QueryConfig;
3839
pub(crate) use rustc_query_system::query::{QueryDescription, QueryVTable};
3940

compiler/rustc_query_impl/src/plumbing.rs

+24
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
//! manage the caches, and so forth.
44
55
use crate::keys::Key;
6+
use crate::on_disk_cache::CacheDecoder;
67
use crate::{on_disk_cache, Queries};
78
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
89
use rustc_data_structures::sync::Lock;
@@ -19,6 +20,7 @@ use rustc_query_system::query::{
1920
QuerySideEffects, QueryStackFrame,
2021
};
2122
use rustc_query_system::Value;
23+
use rustc_serialize::Decodable;
2224
use std::any::Any;
2325
use std::num::NonZeroU64;
2426
use thin_vec::ThinVec;
@@ -253,6 +255,18 @@ macro_rules! get_provider {
253255
};
254256
}
255257

258+
macro_rules! should_ever_cache_on_disk {
259+
([]) => {{
260+
None
261+
}};
262+
([(cache) $($rest:tt)*]) => {{
263+
Some($crate::plumbing::try_load_from_disk::<Self::Value>)
264+
}};
265+
([$other:tt $($modifiers:tt)*]) => {
266+
should_ever_cache_on_disk!([$($modifiers)*])
267+
};
268+
}
269+
256270
pub(crate) fn create_query_frame<
257271
'tcx,
258272
K: Copy + Key + for<'a> HashStable<StableHashingContext<'a>>,
@@ -313,6 +327,16 @@ where
313327
}
314328
}
315329

330+
pub(crate) fn try_load_from_disk<'tcx, V>(
331+
tcx: QueryCtxt<'tcx>,
332+
id: SerializedDepNodeIndex,
333+
) -> Option<V>
334+
where
335+
V: for<'a> Decodable<CacheDecoder<'a, 'tcx>>,
336+
{
337+
tcx.on_disk_cache().as_ref()?.try_load_query_result(*tcx, id)
338+
}
339+
316340
fn force_from_dep_node<'tcx, Q>(tcx: TyCtxt<'tcx>, dep_node: DepNode) -> bool
317341
where
318342
Q: QueryDescription<QueryCtxt<'tcx>>,

0 commit comments

Comments
 (0)