提交 e15383cc 编写于 作者: C Camille GILLOT

Move the DepNode construction to librustc_query_system.

上级 8f3e96d6
......@@ -183,31 +183,10 @@ pub fn $variant(_tcx: TyCtxt<'_>, $(arg: $tuple_arg_ty)*) -> DepNode {
// tuple args
$({
erase!($tuple_arg_ty);
let hash = DepNodeParams::to_fingerprint(&arg, _tcx);
let dep_node = DepNode {
kind: DepKind::$variant,
hash
};
#[cfg(debug_assertions)]
{
if !dep_node.kind.can_reconstruct_query_key() &&
(_tcx.sess.opts.debugging_opts.incremental_info ||
_tcx.sess.opts.debugging_opts.query_dep_graph)
{
_tcx.dep_graph.register_dep_node_debug_str(dep_node, || {
arg.to_debug_str(_tcx)
});
}
}
return dep_node;
return DepNode::construct(_tcx, DepKind::$variant, &arg)
})*
DepNode {
kind: DepKind::$variant,
hash: Fingerprint::ZERO,
}
return DepNode::construct(_tcx, DepKind::$variant, &())
}
)*
}
......
......@@ -98,6 +98,10 @@ fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
fn debug_dep_tasks(&self) -> bool {
self.sess.opts.debugging_opts.dep_tasks
}
fn debug_dep_node(&self) -> bool {
self.sess.opts.debugging_opts.incremental_info
|| self.sess.opts.debugging_opts.query_dep_graph
}
fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool {
// FIXME: This match is just a workaround for incremental bugs and should
......
use crate::dep_graph::{self, DepConstructor, DepNode, DepNodeParams};
use crate::dep_graph::{self, DepNode, DepNodeParams};
use crate::hir::exports::Export;
use crate::hir::map;
use crate::infer::canonical::{self, Canonical};
......
......@@ -348,12 +348,6 @@ fn query_state<'a>(tcx: TyCtxt<$tcx>) -> &'a QueryState<TyCtxt<$tcx>, Self::Cach
&tcx.queries.$name
}
#[allow(unused)]
#[inline(always)]
fn to_dep_node(tcx: TyCtxt<$tcx>, key: &Self::Key) -> DepNode {
DepConstructor::$node(tcx, *key)
}
#[inline]
fn compute(tcx: TyCtxt<'tcx>, key: Self::Key) -> Self::Value {
let provider = tcx.queries.providers.get(key.query_crate())
......
......@@ -64,6 +64,24 @@ pub fn new_no_params(kind: K) -> DepNode<K> {
debug_assert!(!kind.has_params());
DepNode { kind, hash: Fingerprint::ZERO }
}
pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
where
Ctxt: crate::query::QueryContext<DepKind = K>,
Key: DepNodeParams<Ctxt>,
{
let hash = arg.to_fingerprint(tcx);
let dep_node = DepNode { kind, hash };
#[cfg(debug_assertions)]
{
if !kind.can_reconstruct_query_key() && tcx.debug_dep_node() {
tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
}
}
return dep_node;
}
}
impl<K: DepKind> fmt::Debug for DepNode<K> {
......@@ -120,6 +138,12 @@ impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T
}
}
impl<Ctxt: DepContext> DepNodeParams<Ctxt> for () {
fn to_fingerprint(&self, _: Ctxt) -> Fingerprint {
Fingerprint::ZERO
}
}
/// A "work product" corresponds to a `.o` (or other) file that we
/// save in between runs. These IDs do not have a `DefId` but rather
/// some independent path or string that persists between runs without
......
......@@ -28,6 +28,7 @@ pub trait DepContext: Copy {
fn create_stable_hashing_context(&self) -> Self::StableHashingContext;
fn debug_dep_tasks(&self) -> bool;
fn debug_dep_node(&self) -> bool;
/// Try to force a dep node to execute and see if it's green.
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;
......
......@@ -28,7 +28,6 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
pub anon: bool,
pub dep_kind: CTX::DepKind,
pub eval_always: bool,
pub to_dep_node: fn(CTX, &K) -> DepNode<CTX::DepKind>,
// Don't use this method to compute query results, instead use the methods on TyCtxt
pub compute: fn(CTX, K) -> V,
......@@ -40,8 +39,11 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
}
impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind> {
(self.to_dep_node)(tcx, key)
pub(crate) fn to_dep_node(&self, tcx: CTX, key: &K) -> DepNode<CTX::DepKind>
where
K: crate::dep_graph::DepNodeParams<CTX>,
{
DepNode::construct(tcx, self.dep_kind, key)
}
pub(crate) fn compute(&self, tcx: CTX, key: K) -> V {
......@@ -79,7 +81,12 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig<CTX> {
// Don't use this method to access query results, instead use the methods on TyCtxt
fn query_state<'a>(tcx: CTX) -> &'a QueryState<CTX, Self::Cache>;
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>;
fn to_dep_node(tcx: CTX, key: &Self::Key) -> DepNode<CTX::DepKind>
where
Self::Key: crate::dep_graph::DepNodeParams<CTX>,
{
DepNode::construct(tcx, Self::DEP_KIND, key)
}
// Don't use this method to compute query results, instead use the methods on TyCtxt
fn compute(tcx: CTX, key: Self::Key) -> Self::Value;
......@@ -117,7 +124,6 @@ impl<CTX, Q> QueryVtableExt<CTX, Q::Key, Q::Value> for Q
const VTABLE: QueryVtable<CTX, Q::Key, Q::Value> = QueryVtable {
anon: Q::ANON,
dep_kind: Q::DEP_KIND,
to_dep_node: Q::to_dep_node,
eval_always: Q::EVAL_ALWAYS,
compute: Q::compute,
hash_result: Q::hash_result,
......
......@@ -392,7 +392,7 @@ fn try_execute_query<CTX, C>(
) -> C::Stored
where
C: QueryCache,
C::Key: Eq + Clone + Debug,
C::Key: Eq + Clone + Debug + crate::dep_graph::DepNodeParams<CTX>,
C::Stored: Clone,
CTX: QueryContext,
{
......@@ -616,6 +616,7 @@ fn force_query_with_job<C, CTX>(
pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key) -> Q::Stored
where
Q: QueryDescription<CTX>,
Q::Key: crate::dep_graph::DepNodeParams<CTX>,
CTX: QueryContext,
{
debug!("ty::query::get_query<{}>(key={:?}, span={:?})", Q::NAME, key, span);
......@@ -642,6 +643,7 @@ pub fn get_query<Q, CTX>(tcx: CTX, span: Span, key: Q::Key) -> Q::Stored
pub fn ensure_query<Q, CTX>(tcx: CTX, key: Q::Key)
where
Q: QueryDescription<CTX>,
Q::Key: crate::dep_graph::DepNodeParams<CTX>,
CTX: QueryContext,
{
if Q::EVAL_ALWAYS {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册