From 1b2deaf57aeec36ede38a81184fbafebb64fd4ac Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Fri, 6 Mar 2020 22:15:46 +0100 Subject: [PATCH] Monomorphise force_query_with_job. --- src/librustc_query_system/query/config.rs | 25 ++++++++++++++++++ src/librustc_query_system/query/plumbing.rs | 29 ++++++++++++--------- 2 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/librustc_query_system/query/config.rs b/src/librustc_query_system/query/config.rs index 710ec3bfb0b3..37a304cb5071 100644 --- a/src/librustc_query_system/query/config.rs +++ b/src/librustc_query_system/query/config.rs @@ -24,6 +24,15 @@ pub trait QueryConfig { type Stored: Clone; } +pub(crate) struct QueryVtable { + pub eval_always: bool, + + // Don't use this method to compute query results, instead use the methods on TyCtxt + pub compute: fn(CTX, K) -> V, + + pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option, +} + pub trait QueryAccessors: QueryConfig { const ANON: bool; const EVAL_ALWAYS: bool; @@ -60,6 +69,22 @@ pub trait QueryDescription: QueryAccessors { } } +pub(crate) trait QueryVtableExt { + const VTABLE: QueryVtable; +} + +impl QueryVtableExt for Q +where + CTX: QueryContext, + Q: QueryDescription, +{ + const VTABLE: QueryVtable = QueryVtable { + eval_always: Q::EVAL_ALWAYS, + compute: Q::compute, + hash_result: Q::hash_result, + }; +} + impl QueryDescription for M where M: QueryAccessors, diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index 0aeec269e617..21cd7ce567a2 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -5,7 +5,7 @@ use crate::dep_graph::{DepKind, DepNode}; use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; use crate::query::caches::QueryCache; -use crate::query::config::QueryDescription; +use crate::query::config::{QueryDescription, QueryVtable, QueryVtableExt}; use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId}; use crate::query::QueryContext; @@ -406,7 +406,7 @@ where // expensive for some `DepKind`s. if !tcx.dep_graph().is_fully_enabled() { let null_dep_node = DepNode::new_no_params(DepKind::NULL); - return force_query_with_job::(tcx, key, job, null_dep_node).0; + return force_query_with_job(tcx, key, job, null_dep_node, &Q::VTABLE).0; } if Q::ANON { @@ -455,7 +455,7 @@ where } } - let (result, dep_node_index) = force_query_with_job::(tcx, key, job, dep_node); + let (result, dep_node_index) = force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE); tcx.dep_graph().read_index(dep_node_index); result } @@ -549,14 +549,17 @@ fn incremental_verify_ich( } #[inline(always)] -fn force_query_with_job( +fn force_query_with_job( tcx: CTX, - key: Q::Key, - job: JobOwner<'_, CTX, Q::Cache>, + key: C::Key, + job: JobOwner<'_, CTX, C>, dep_node: DepNode, -) -> (Q::Stored, DepNodeIndex) + query: &QueryVtable, +) -> (C::Stored, DepNodeIndex) where - Q: QueryDescription, + C: QueryCache, + C::Key: Eq + Clone + Debug, + C::Stored: Clone, CTX: QueryContext, { // If the following assertion triggers, it can have two reasons: @@ -577,16 +580,16 @@ where let ((result, dep_node_index), diagnostics) = with_diagnostics(|diagnostics| { tcx.start_query(job.id, diagnostics, |tcx| { - if Q::EVAL_ALWAYS { + if query.eval_always { tcx.dep_graph().with_eval_always_task( dep_node, tcx, key, - Q::compute, - Q::hash_result, + query.compute, + query.hash_result, ) } else { - tcx.dep_graph().with_task(dep_node, tcx, key, Q::compute, Q::hash_result) + tcx.dep_graph().with_task(dep_node, tcx, key, query.compute, query.hash_result) } }) }); @@ -684,7 +687,7 @@ where #[cfg(parallel_compiler)] TryGetJob::JobCompleted(_) => return, }; - force_query_with_job::(tcx, key, job, dep_node); + force_query_with_job(tcx, key, job, dep_node, &Q::VTABLE); }, ); }