Skip to content

Commit 8f3e96d

Browse files
committed
Monomorphise try_execute_query.
1 parent 1c7376e commit 8f3e96d

File tree

2 files changed

+38
-43
lines changed

2 files changed

+38
-43
lines changed

src/librustc_query_system/query/config.rs

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
2828
pub anon: bool,
2929
pub dep_kind: CTX::DepKind,
3030
pub eval_always: bool,
31+
pub to_dep_node: fn(CTX, &K) -> DepNode<CTX::DepKind>,
3132

3233
// Don't use this method to compute query results, instead use the methods on TyCtxt
3334
pub compute: fn(CTX, K) -> V,
@@ -39,6 +40,10 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
3940
}
4041

4142
impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
43+
pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind> {
44+
(self.to_dep_node)(tcx, key)
45+
}
46+
4247
pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
4348
(self.compute)(tcx, key)
4449
}
@@ -112,6 +117,7 @@ where
112117
const VTABLE: QueryVtable<CTX, Q::Key, Q::Value> = QueryVtable {
113118
anon: Q::ANON,
114119
dep_kind: Q::DEP_KIND,
120+
to_dep_node: Q::to_dep_node,
115121
eval_always: Q::EVAL_ALWAYS,
116122
compute: Q::compute,
117123
hash_result: Q::hash_result,

src/librustc_query_system/query/plumbing.rs

+32-43
Original file line numberDiff line numberDiff line change
@@ -382,17 +382,21 @@ where
382382
}
383383

384384
#[inline(always)]
385-
fn try_execute_query<Q, CTX>(
385+
fn try_execute_query<CTX, C>(
386386
tcx: CTX,
387+
state: &QueryState<CTX, C>,
387388
span: Span,
388-
key: Q::Key,
389-
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache>::Sharded>,
390-
) -> Q::Stored
389+
key: C::Key,
390+
lookup: QueryLookup<'_, CTX, C::Key, C::Sharded>,
391+
query: &QueryVtable<CTX, C::Key, C::Value>,
392+
) -> C::Stored
391393
where
392-
Q: QueryDescription<CTX>,
394+
C: QueryCache,
395+
C::Key: Eq + Clone + Debug,
396+
C::Stored: Clone,
393397
CTX: QueryContext,
394398
{
395-
let job = match JobOwner::try_start(tcx, Q::query_state(tcx), span, &key, lookup, &Q::VTABLE) {
399+
let job = match JobOwner::try_start(tcx, state, span, &key, lookup, query) {
396400
TryGetJob::NotYetStarted(job) => job,
397401
TryGetJob::Cycle(result) => return result,
398402
#[cfg(parallel_compiler)]
@@ -406,18 +410,32 @@ where
406410
// expensive for some `DepKind`s.
407411
if !tcx.dep_graph().is_fully_enabled() {
408412
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
409-
return force_query_with_job(tcx, key, job, null_dep_node, &Q::VTABLE).0;
413+
return force_query_with_job(tcx, key, job, null_dep_node, query).0;
410414
}
411415

412-
if Q::ANON {
413-
let (result, dep_node_index) = try_execute_anon_query(tcx, key, job.id, &Q::VTABLE);
416+
if query.anon {
417+
let prof_timer = tcx.profiler().query_provider();
418+
419+
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
420+
tcx.start_query(job.id, diagnostics, |tcx| {
421+
tcx.dep_graph().with_anon_task(query.dep_kind, || query.compute(tcx, key))
422+
})
423+
});
424+
425+
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
426+
427+
tcx.dep_graph().read_index(dep_node_index);
428+
429+
if unlikely!(!diagnostics.is_empty()) {
430+
tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
431+
}
414432

415433
return job.complete(tcx, result, dep_node_index);
416434
}
417435

418-
let dep_node = Q::to_dep_node(tcx, &key);
436+
let dep_node = query.to_dep_node(tcx, &key);
419437

420-
if !Q::EVAL_ALWAYS {
438+
if !query.eval_always {
421439
// The diagnostics for this query will be
422440
// promoted to the current session during
423441
// `try_mark_green()`, so we can ignore them here.
@@ -431,7 +449,7 @@ where
431449
prev_dep_node_index,
432450
dep_node_index,
433451
&dep_node,
434-
&Q::VTABLE,
452+
query,
435453
),
436454
dep_node_index,
437455
)
@@ -442,40 +460,11 @@ where
442460
}
443461
}
444462

445-
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE);
463+
let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, query);
446464
tcx.dep_graph().read_index(dep_node_index);
447465
result
448466
}
449467

450-
fn try_execute_anon_query<CTX, K, V>(
451-
tcx: CTX,
452-
key: K,
453-
job_id: QueryJobId<CTX::DepKind>,
454-
query: &QueryVtable<CTX, K, V>,
455-
) -> (V, DepNodeIndex)
456-
where
457-
CTX: QueryContext,
458-
{
459-
debug_assert!(query.anon);
460-
let prof_timer = tcx.profiler().query_provider();
461-
462-
let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| {
463-
tcx.start_query(job_id, diagnostics, |tcx| {
464-
tcx.dep_graph().with_anon_task(query.dep_kind, || query.compute(tcx, key))
465-
})
466-
});
467-
468-
prof_timer.finish_with_query_invocation_id(dep_node_index.into());
469-
470-
tcx.dep_graph().read_index(dep_node_index);
471-
472-
if unlikely!(!diagnostics.is_empty()) {
473-
tcx.store_diagnostics_for_anon_node(dep_node_index, diagnostics);
474-
}
475-
476-
(result, dep_node_index)
477-
}
478-
479468
fn load_from_disk_and_cache_in_memory<CTX, K, V>(
480469
tcx: CTX,
481470
key: K,
@@ -639,7 +628,7 @@ where
639628
tcx.dep_graph().read_index(index);
640629
value.clone()
641630
},
642-
|key, lookup| try_execute_query::<Q, _>(tcx, span, key, lookup),
631+
|key, lookup| try_execute_query(tcx, Q::query_state(tcx), span, key, lookup, &Q::VTABLE),
643632
)
644633
}
645634

0 commit comments

Comments
 (0)