Skip to content

Commit 602d3cb

Browse files
committed
Invoke callbacks from rustc_middle.
1 parent b09de95 commit 602d3cb

File tree

9 files changed

+42
-47
lines changed

9 files changed

+42
-47
lines changed

Cargo.lock

-1
Original file line numberDiff line numberDiff line change
@@ -4319,7 +4319,6 @@ dependencies = [
43194319
"rustc_serialize",
43204320
"rustc_session",
43214321
"rustc_span",
4322-
"tracing",
43234322
]
43244323

43254324
[[package]]

compiler/rustc_middle/src/dep_graph/mod.rs

+30
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,34 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
9999
fn is_eval_always(&self, kind: DepKind) -> bool {
100100
self.query_kind(kind).is_eval_always
101101
}
102+
103+
fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool {
104+
debug!("try_force_from_dep_node({:?}) --- trying to force", dep_node);
105+
106+
// We must avoid ever having to call `force_from_dep_node()` for a
107+
// `DepNode::codegen_unit`:
108+
// Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we
109+
// would always end up having to evaluate the first caller of the
110+
// `codegen_unit` query that *is* reconstructible. This might very well be
111+
// the `compile_codegen_unit` query, thus re-codegenning the whole CGU just
112+
// to re-trigger calling the `codegen_unit` query with the right key. At
113+
// that point we would already have re-done all the work we are trying to
114+
// avoid doing in the first place.
115+
// The solution is simple: Just explicitly call the `codegen_unit` query for
116+
// each CGU, right after partitioning. This way `try_mark_green` will always
117+
// hit the cache instead of having to go through `force_from_dep_node`.
118+
// This assertion makes sure, we actually keep applying the solution above.
119+
debug_assert!(
120+
dep_node.kind != DepKind::codegen_unit,
121+
"calling force_from_dep_node() on DepKind::codegen_unit"
122+
);
123+
124+
let cb = self.query_kind(dep_node.kind);
125+
(cb.force_from_dep_node)(*self, dep_node)
126+
}
127+
128+
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode) {
129+
let cb = self.query_kind(dep_node.kind);
130+
(cb.try_load_from_on_disk_cache)(*self, dep_node)
131+
}
102132
}

compiler/rustc_query_impl/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ doctest = false
99
[dependencies]
1010
measureme = "10.0.0"
1111
rustc-rayon-core = "0.3.1"
12-
tracing = "0.1"
1312
rustc_ast = { path = "../rustc_ast" }
1413
rustc_data_structures = { path = "../rustc_data_structures" }
1514
rustc_errors = { path = "../rustc_errors" }

compiler/rustc_query_impl/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
extern crate rustc_macros;
1414
#[macro_use]
1515
extern crate rustc_middle;
16-
#[macro_use]
17-
extern crate tracing;
1816

1917
use rustc_data_structures::fingerprint::Fingerprint;
2018
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};

compiler/rustc_query_impl/src/on_disk_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'sess> rustc_middle::ty::OnDiskCache<'sess> for OnDiskCache<'sess> {
219219
// Do this *before* we clone 'latest_foreign_def_path_hashes', since
220220
// loading existing queries may cause us to create new DepNodes, which
221221
// may in turn end up invoking `store_foreign_def_id_hash`
222-
tcx.dep_graph.exec_cache_promotions(QueryCtxt::from_tcx(tcx));
222+
tcx.dep_graph.exec_cache_promotions(tcx);
223223

224224
*self.serialized_data.write() = None;
225225
}

compiler/rustc_query_impl/src/plumbing.rs

+1-31
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! manage the caches, and so forth.
44
55
use crate::{on_disk_cache, queries, Queries};
6-
use rustc_middle::dep_graph::{DepKind, DepNode, DepNodeIndex, SerializedDepNodeIndex};
6+
use rustc_middle::dep_graph::{DepKind, DepNodeIndex, SerializedDepNodeIndex};
77
use rustc_middle::ty::tls::{self, ImplicitCtxt};
88
use rustc_middle::ty::{self, TyCtxt};
99
use rustc_query_system::dep_graph::HasDepContext;
@@ -53,36 +53,6 @@ impl QueryContext for QueryCtxt<'tcx> {
5353
self.queries.try_collect_active_jobs(**self)
5454
}
5555

56-
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode) {
57-
let cb = &super::QUERY_CALLBACKS[dep_node.kind as usize];
58-
(cb.try_load_from_on_disk_cache)(**self, dep_node)
59-
}
60-
61-
fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool {
62-
debug!("try_force_from_dep_node({:?}) --- trying to force", dep_node);
63-
64-
// We must avoid ever having to call `force_from_dep_node()` for a
65-
// `DepNode::codegen_unit`:
66-
// Since we cannot reconstruct the query key of a `DepNode::codegen_unit`, we
67-
// would always end up having to evaluate the first caller of the
68-
// `codegen_unit` query that *is* reconstructible. This might very well be
69-
// the `compile_codegen_unit` query, thus re-codegenning the whole CGU just
70-
// to re-trigger calling the `codegen_unit` query with the right key. At
71-
// that point we would already have re-done all the work we are trying to
72-
// avoid doing in the first place.
73-
// The solution is simple: Just explicitly call the `codegen_unit` query for
74-
// each CGU, right after partitioning. This way `try_mark_green` will always
75-
// hit the cache instead of having to go through `force_from_dep_node`.
76-
// This assertion makes sure, we actually keep applying the solution above.
77-
debug_assert!(
78-
dep_node.kind != DepKind::codegen_unit,
79-
"calling force_from_dep_node() on DepKind::codegen_unit"
80-
);
81-
82-
let cb = &super::QUERY_CALLBACKS[dep_node.kind as usize];
83-
(cb.force_from_dep_node)(**self, dep_node)
84-
}
85-
8656
// Interactions with on_disk_cache
8757
fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects {
8858
self.queries

compiler/rustc_query_system/src/dep_graph/graph.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ impl<K: DepKind> DepGraph<K> {
576576
"try_mark_previous_green({:?}) --- trying to force dependency {:?}",
577577
dep_node, dep_dep_node
578578
);
579-
if !tcx.try_force_from_dep_node(dep_dep_node) {
579+
if !tcx.dep_context().try_force_from_dep_node(dep_dep_node) {
580580
// The DepNode could not be forced.
581581
debug!(
582582
"try_mark_previous_green({:?}) - END - dependency {:?} could not be forced",
@@ -741,16 +741,15 @@ impl<K: DepKind> DepGraph<K> {
741741
//
742742
// This method will only load queries that will end up in the disk cache.
743743
// Other queries will not be executed.
744-
pub fn exec_cache_promotions<Ctxt: QueryContext<DepKind = K>>(&self, qcx: Ctxt) {
745-
let tcx = qcx.dep_context();
744+
pub fn exec_cache_promotions<Ctxt: DepContext<DepKind = K>>(&self, tcx: Ctxt) {
746745
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
747746

748747
let data = self.data.as_ref().unwrap();
749748
for prev_index in data.colors.values.indices() {
750749
match data.colors.get(prev_index) {
751750
Some(DepNodeColor::Green(_)) => {
752751
let dep_node = data.previous.index_to_node(prev_index);
753-
qcx.try_load_from_on_disk_cache(&dep_node);
752+
tcx.try_load_from_on_disk_cache(&dep_node);
754753
}
755754
None | Some(DepNodeColor::Red) => {
756755
// We can skip red nodes because a node can only be marked

compiler/rustc_query_system/src/dep_graph/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ pub trait DepContext: Copy {
3737
fn is_eval_always(&self, kind: Self::DepKind) -> bool;
3838

3939
fn fingerprint_style(&self, kind: Self::DepKind) -> FingerprintStyle;
40+
41+
/// Try to force a dep node to execute and see if it's green.
42+
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;
43+
44+
/// Load data from the on-disk cache.
45+
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
4046
}
4147

4248
pub trait HasDepContext: Copy {

compiler/rustc_query_system/src/query/mod.rs

+1-7
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::{DepNode, DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
17+
use crate::dep_graph::{DepNodeIndex, HasDepContext, SerializedDepNodeIndex};
1818

1919
use rustc_data_structures::sync::Lock;
2020
use rustc_data_structures::thin_vec::ThinVec;
@@ -122,12 +122,6 @@ pub trait QueryContext: HasDepContext {
122122

123123
fn try_collect_active_jobs(&self) -> Option<QueryMap<Self::DepKind>>;
124124

125-
/// Load data from the on-disk cache.
126-
fn try_load_from_on_disk_cache(&self, dep_node: &DepNode<Self::DepKind>);
127-
128-
/// Try to force a dep node to execute and see if it's green.
129-
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool;
130-
131125
/// Load side effects associated to the node in the previous session.
132126
fn load_side_effects(&self, prev_dep_node_index: SerializedDepNodeIndex) -> QuerySideEffects;
133127

0 commit comments

Comments
 (0)