Skip to content

Commit 211b05a

Browse files
committed
Don't require a QueryContext to access the DepGraph.
1 parent 7794fbb commit 211b05a

File tree

6 files changed

+13
-14
lines changed

6 files changed

+13
-14
lines changed

compiler/rustc_middle/src/dep_graph/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
111111
|| self.sess.opts.debugging_opts.query_dep_graph
112112
}
113113

114+
#[inline]
115+
fn dep_graph(&self) -> &DepGraph {
116+
&self.dep_graph
117+
}
118+
114119
fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool {
115120
// FIXME: This match is just a workaround for incremental bugs and should
116121
// be removed. https://github.com/rust-lang/rust/issues/62649 is one such

compiler/rustc_middle/src/ty/query/plumbing.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! generate the actual methods on tcx which find and execute the provider,
33
//! manage the caches, and so forth.
44
5-
use crate::dep_graph::DepGraph;
65
use crate::ty::query::Query;
76
use crate::ty::tls::{self, ImplicitCtxt};
87
use crate::ty::{self, TyCtxt};
@@ -30,10 +29,6 @@ impl QueryContext for TyCtxt<'tcx> {
3029
TyCtxt::def_path_str(*self, def_id)
3130
}
3231

33-
fn dep_graph(&self) -> &DepGraph {
34-
&self.dep_graph
35-
}
36-
3732
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>> {
3833
tls::with_related_context(*self, |icx| icx.query)
3934
}

compiler/rustc_query_system/src/cache.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! Cache for candidate selection.
22
3-
use crate::dep_graph::DepNodeIndex;
4-
use crate::query::QueryContext;
3+
use crate::dep_graph::{DepContext, DepNodeIndex};
54

65
use rustc_data_structures::fx::FxHashMap;
76
use rustc_data_structures::sync::HashMapExt;
@@ -28,7 +27,7 @@ impl<Key, Value> Cache<Key, Value> {
2827
}
2928

3029
impl<Key: Eq + Hash, Value: Clone> Cache<Key, Value> {
31-
pub fn get<CTX: QueryContext>(&self, key: &Key, tcx: CTX) -> Option<Value> {
30+
pub fn get<CTX: DepContext>(&self, key: &Key, tcx: CTX) -> Option<Value> {
3231
Some(self.hashmap.borrow().get(key)?.get(tcx))
3332
}
3433

@@ -55,7 +54,7 @@ impl<T: Clone> WithDepNode<T> {
5554
WithDepNode { dep_node, cached_value }
5655
}
5756

58-
pub fn get<CTX: QueryContext>(&self, tcx: CTX) -> T {
57+
pub fn get<CTX: DepContext>(&self, tcx: CTX) -> T {
5958
tcx.dep_graph().read_index(self.dep_node);
6059
self.cached_value.clone()
6160
}

compiler/rustc_query_system/src/dep_graph/dep_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ impl<K: DepKind> DepNode<K> {
7979

8080
pub fn construct<Ctxt, Key>(tcx: Ctxt, kind: K, arg: &Key) -> DepNode<K>
8181
where
82-
Ctxt: crate::query::QueryContext<DepKind = K>,
82+
Ctxt: super::DepContext<DepKind = K>,
8383
Key: DepNodeParams<Ctxt>,
8484
{
8585
let hash = arg.to_fingerprint(tcx);

compiler/rustc_query_system/src/dep_graph/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub trait DepContext: Copy {
2929
fn debug_dep_tasks(&self) -> bool;
3030
fn debug_dep_node(&self) -> bool;
3131

32+
/// Access the DepGraph.
33+
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
34+
3235
/// Try to force a dep node to execute and see if it's green.
3336
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;
3437

compiler/rustc_query_system/src/query/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub use self::caches::{
1414
mod config;
1515
pub use self::config::{QueryAccessors, QueryConfig, QueryDescription};
1616

17-
use crate::dep_graph::{DepContext, DepGraph};
17+
use crate::dep_graph::DepContext;
1818
use crate::query::job::QueryMap;
1919

2020
use rustc_data_structures::stable_hasher::HashStable;
@@ -32,9 +32,6 @@ pub trait QueryContext: DepContext {
3232
/// Get string representation from DefPath.
3333
fn def_path_str(&self, def_id: DefId) -> String;
3434

35-
/// Access the DepGraph.
36-
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
37-
3835
/// Get the query information from the TLS context.
3936
fn current_query_job(&self) -> Option<QueryJobId<Self::DepKind>>;
4037

0 commit comments

Comments
 (0)