Skip to content

Commit 4fcc745

Browse files
committed
Simplify try_load_from_on_disk_cache
1 parent 83b6dc9 commit 4fcc745

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

Diff for: compiler/rustc_query_impl/src/plumbing.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -301,18 +301,20 @@ pub(crate) fn create_query_frame<
301301
QueryStackFrame::new(name, description, span, def_kind, hash)
302302
}
303303

304-
pub(crate) fn try_load_from_on_disk_cache<'tcx, K: DepNodeParams<TyCtxt<'tcx>>, V>(
304+
pub(crate) fn try_load_from_on_disk_cache<'tcx, Q, V>(
305305
tcx: TyCtxt<'tcx>,
306306
dep_node: DepNode,
307-
cache_on_disk: fn(TyCtxt<'tcx>, &K) -> bool,
308-
cache_query_deps: fn(TyCtxt<'tcx>, K) -> V,
309-
) {
307+
cache_query_deps: fn(TyCtxt<'tcx>, Q::Key) -> V,
308+
) where
309+
Q: QueryDescription<QueryCtxt<'tcx>>,
310+
Q::Key: DepNodeParams<TyCtxt<'tcx>>,
311+
{
310312
debug_assert!(tcx.dep_graph.is_green(&dep_node));
311313

312-
let key = K::recover(tcx, &dep_node).unwrap_or_else(|| {
314+
let key = Q::Key::recover(tcx, &dep_node).unwrap_or_else(|| {
313315
panic!("Failed to recover key for {:?} with hash {}", dep_node, dep_node.hash)
314316
});
315-
if cache_on_disk(tcx, &key) {
317+
if Q::cache_on_disk(tcx, &key) {
316318
let _ = cache_query_deps(tcx, key);
317319
}
318320
}
@@ -434,7 +436,6 @@ macro_rules! define_queries {
434436
#[allow(nonstandard_style)]
435437
mod query_callbacks {
436438
use super::*;
437-
use rustc_query_system::query::QueryDescription;
438439
use rustc_query_system::dep_graph::FingerprintStyle;
439440

440441
// We use this for most things when incr. comp. is turned off.
@@ -495,7 +496,7 @@ macro_rules! define_queries {
495496
type Q<'tcx> = queries::$name<'tcx>;
496497

497498
$crate::plumbing::query_callback::<Q<'_>>(
498-
|tcx, key| $crate::plumbing::try_load_from_on_disk_cache::<<Q<'_> as QueryConfig>::Key, _>(tcx, key, <Q<'_>>::cache_on_disk, TyCtxt::$name),
499+
|tcx, key| $crate::plumbing::try_load_from_on_disk_cache::<Q<'_>, _>(tcx, key, TyCtxt::$name),
499500
|tcx, key| $crate::plumbing::force_from_dep_node::<Q<'_>>(tcx, key),
500501
is_anon,
501502
is_eval_always

0 commit comments

Comments
 (0)