From a51ad889dd712e8b665656ebf08a2f85034f7415 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 18 Mar 2020 21:02:02 +0100 Subject: [PATCH] Decouple from DepKind. --- src/librustc/dep_graph/mod.rs | 6 ++++++ src/librustc/ty/query/config.rs | 3 +-- src/librustc/ty/query/plumbing.rs | 21 +++++++++++---------- src/librustc_query_system/dep_graph/mod.rs | 4 ++++ 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/librustc/dep_graph/mod.rs b/src/librustc/dep_graph/mod.rs index 3c39597584df..dfb962227ffe 100644 --- a/src/librustc/dep_graph/mod.rs +++ b/src/librustc/dep_graph/mod.rs @@ -27,6 +27,8 @@ pub type PreviousDepGraph = rustc_query_system::dep_graph::PreviousDepGraph; impl rustc_query_system::dep_graph::DepKind for DepKind { + const NULL: Self = DepKind::Null; + fn is_eval_always(&self) -> bool { DepKind::is_eval_always(self) } @@ -82,6 +84,10 @@ impl rustc_query_system::dep_graph::DepKind for DepKind { op(icx.task_deps) }) } + + fn can_reconstruct_query_key(&self) -> bool { + DepKind::can_reconstruct_query_key(self) + } } impl<'tcx> DepContext for TyCtxt<'tcx> { diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 77feb7f4df3a..c3b0103cc0c2 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -1,6 +1,5 @@ //! Query configuration and description traits. -use crate::dep_graph::DepKind; use crate::dep_graph::SerializedDepNodeIndex; use crate::ty::query::caches::QueryCache; use crate::ty::query::plumbing::CycleError; @@ -23,7 +22,7 @@ pub trait QueryConfig { type Value: Clone; } -pub trait QueryContext: DepContext { +pub trait QueryContext: DepContext { type Query; /// Access the session. diff --git a/src/librustc/ty/query/plumbing.rs b/src/librustc/ty/query/plumbing.rs index 2d1614d6ccd9..ede1ccdbc04b 100644 --- a/src/librustc/ty/query/plumbing.rs +++ b/src/librustc/ty/query/plumbing.rs @@ -2,7 +2,7 @@ //! generate the actual methods on tcx which find and execute the provider, //! manage the caches, and so forth. -use crate::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex}; +use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex}; use crate::ty::query::caches::QueryCache; use crate::ty::query::config::{QueryContext, QueryDescription}; use crate::ty::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId}; @@ -17,6 +17,7 @@ use rustc_data_structures::sharded::Sharded; use rustc_data_structures::sync::{Lock, LockGuard}; use rustc_data_structures::thin_vec::ThinVec; use rustc_errors::{struct_span_err, Diagnostic, DiagnosticBuilder, FatalError, Handler, Level}; +use rustc_query_system::dep_graph::{DepKind, DepNode}; use rustc_session::Session; use rustc_span::def_id::DefId; use rustc_span::source_map::DUMMY_SP; @@ -102,7 +103,7 @@ impl> QueryState { pub(super) fn try_collect_active_jobs( &self, - kind: DepKind, + kind: CTX::DepKind, make_query: fn(C::Key) -> CTX::Query, jobs: &mut FxHashMap, QueryJobInfo>, ) -> Option<()> @@ -375,7 +376,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline(always)] fn start_query( self, - token: QueryJobId, + token: QueryJobId, diagnostics: Option<&Lock>>, compute: F, ) -> R @@ -570,7 +571,7 @@ impl<'tcx> TyCtxt<'tcx> { // Fast path for when incr. comp. is off. `to_dep_node` is // expensive for some `DepKind`s. if !self.dep_graph.is_fully_enabled() { - let null_dep_node = DepNode::new_no_params(crate::dep_graph::DepKind::Null); + let null_dep_node = DepNode::new_no_params(DepKind::NULL); return self.force_query_with_job::(key, job, null_dep_node).0; } @@ -634,7 +635,7 @@ impl<'tcx> TyCtxt<'tcx> { key: Q::Key, prev_dep_node_index: SerializedDepNodeIndex, dep_node_index: DepNodeIndex, - dep_node: &DepNode, + dep_node: &DepNode, ) -> Q::Value { // Note this function can be called concurrently from the same query // We must ensure that this is handled correctly. @@ -689,7 +690,7 @@ impl<'tcx> TyCtxt<'tcx> { fn incremental_verify_ich>>( self, result: &Q::Value, - dep_node: &DepNode, + dep_node: &DepNode, dep_node_index: DepNodeIndex, ) { use rustc_data_structures::fingerprint::Fingerprint; @@ -716,8 +717,8 @@ impl<'tcx> TyCtxt<'tcx> { fn force_query_with_job> + 'tcx>( self, key: Q::Key, - job: JobOwner<'tcx, TyCtxt<'tcx>, Q::Cache>, - dep_node: DepNode, + job: JobOwner<'tcx, Self, Q::Cache>, + dep_node: DepNode, ) -> (Q::Value, DepNodeIndex) { // If the following assertion triggers, it can have two reasons: // 1. Something is wrong with DepNode creation, either here or @@ -754,7 +755,7 @@ impl<'tcx> TyCtxt<'tcx> { prof_timer.finish_with_query_invocation_id(dep_node_index.into()); if unlikely!(!diagnostics.is_empty()) { - if dep_node.kind != crate::dep_graph::DepKind::Null { + if dep_node.kind != DepKind::NULL { self.queries.on_disk_cache.store_diagnostics(dep_node_index, diagnostics); } } @@ -803,7 +804,7 @@ impl<'tcx> TyCtxt<'tcx> { self, key: Q::Key, span: Span, - dep_node: DepNode, + dep_node: DepNode, ) { // We may be concurrently trying both execute and force a query. // Ensure that only one of them runs the query. diff --git a/src/librustc_query_system/dep_graph/mod.rs b/src/librustc_query_system/dep_graph/mod.rs index 825b341cd146..888151782c7d 100644 --- a/src/librustc_query_system/dep_graph/mod.rs +++ b/src/librustc_query_system/dep_graph/mod.rs @@ -54,6 +54,8 @@ pub trait DepContext: Copy { /// Describe the different families of dependency nodes. pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash { + const NULL: Self; + /// Return whether this kind always require evaluation. fn is_eval_always(&self) -> bool; @@ -72,4 +74,6 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash { fn read_deps(op: OP) -> () where OP: for<'a> FnOnce(Option<&'a Lock>>) -> (); + + fn can_reconstruct_query_key(&self) -> bool; }