Skip to content

Commit 1b2deaf

Browse files
committed
Monomorphise force_query_with_job.
1 parent bd0bacc commit 1b2deaf

File tree

2 files changed

+41
-13
lines changed

2 files changed

+41
-13
lines changed

src/librustc_query_system/query/config.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ pub trait QueryConfig<CTX> {
2424
type Stored: Clone;
2525
}
2626

27+
pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
28+
pub eval_always: bool,
29+
30+
// Don't use this method to compute query results, instead use the methods on TyCtxt
31+
pub compute: fn(CTX, K) -> V,
32+
33+
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
34+
}
35+
2736
pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
2837
const ANON: bool;
2938
const EVAL_ALWAYS: bool;
@@ -60,6 +69,22 @@ pub trait QueryDescription<CTX: QueryContext>: QueryAccessors<CTX> {
6069
}
6170
}
6271

72+
pub(crate) trait QueryVtableExt<CTX: QueryContext, K, V> {
73+
const VTABLE: QueryVtable<CTX, K, V>;
74+
}
75+
76+
impl<CTX, Q> QueryVtableExt<CTX, Q::Key, Q::Value> for Q
77+
where
78+
CTX: QueryContext,
79+
Q: QueryDescription<CTX>,
80+
{
81+
const VTABLE: QueryVtable<CTX, Q::Key, Q::Value> = QueryVtable {
82+
eval_always: Q::EVAL_ALWAYS,
83+
compute: Q::compute,
84+
hash_result: Q::hash_result,
85+
};
86+
}
87+
6388
impl<CTX: QueryContext, M> QueryDescription<CTX> for M
6489
where
6590
M: QueryAccessors<CTX, Key = DefId>,

src/librustc_query_system/query/plumbing.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use crate::dep_graph::{DepKind, DepNode};
66
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
77
use crate::query::caches::QueryCache;
8-
use crate::query::config::QueryDescription;
8+
use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt};
99
use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
1010
use crate::query::QueryContext;
1111

@@ -406,7 +406,7 @@ where
406406
// expensive for some `DepKind`s.
407407
if !tcx.dep_graph().is_fully_enabled() {
408408
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
409-
return force_query_with_job::<Q, _>(tcx, key, job, null_dep_node).0;
409+
return force_query_with_job(tcx, key, job, null_dep_node, &Q::VTABLE).0;
410410
}
411411

412412
if Q::ANON {
@@ -455,7 +455,7 @@ where
455455
}
456456
}
457457

458-
let (result, dep_node_index) = force_query_with_job::<Q, _>(tcx, key, job, dep_node);
458+
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE);
459459
tcx.dep_graph().read_index(dep_node_index);
460460
result
461461
}
@@ -549,14 +549,17 @@ fn incremental_verify_ich<Q, CTX>(
549549
}
550550

551551
#[inline(always)]
552-
fn force_query_with_job<Q, CTX>(
552+
fn force_query_with_job<C, CTX>(
553553
tcx: CTX,
554-
key: Q::Key,
555-
job: JobOwner<'_, CTX, Q::Cache>,
554+
key: C::Key,
555+
job: JobOwner<'_, CTX, C>,
556556
dep_node: DepNode<CTX::DepKind>,
557-
) -> (Q::Stored, DepNodeIndex)
557+
query: &QueryVtable<CTX, C::Key, C::Value>,
558+
) -> (C::Stored, DepNodeIndex)
558559
where
559-
Q: QueryDescription<CTX>,
560+
C: QueryCache,
561+
C::Key: Eq + Clone + Debug,
562+
C::Stored: Clone,
560563
CTX: QueryContext,
561564
{
562565
// If the following assertion triggers, it can have two reasons:
@@ -577,16 +580,16 @@ where
577580

578581
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
579582
tcx.start_query(job.id, diagnostics, |tcx| {
580-
if Q::EVAL_ALWAYS {
583+
if query.eval_always {
581584
tcx.dep_graph().with_eval_always_task(
582585
dep_node,
583586
tcx,
584587
key,
585-
Q::compute,
586-
Q::hash_result,
588+
query.compute,
589+
query.hash_result,
587590
)
588591
} else {
589-
tcx.dep_graph().with_task(dep_node, tcx, key, Q::compute, Q::hash_result)
592+
tcx.dep_graph().with_task(dep_node, tcx, key, query.compute, query.hash_result)
590593
}
591594
})
592595
});
@@ -684,7 +687,7 @@ where
684687
#[cfg(parallel_compiler)]
685688
TryGetJob::JobCompleted(_) => return,
686689
};
687-
force_query_with_job::<Q, _>(tcx, key, job, dep_node);
690+
force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE);
688691
},
689692
);
690693
}

0 commit comments

Comments
 (0)