Skip to content

Commit 7c877d9

Browse files
committed
Remove DepContext.
It's no longer needed now that we can access `TyCtxt` directly.
1 parent 414be2e commit 7c877d9

12 files changed

Lines changed: 133 additions & 202 deletions

File tree

compiler/rustc_interface/src/callbacks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use std::fmt;
1313

1414
use rustc_errors::{DiagInner, TRACK_DIAGNOSTIC};
1515
use rustc_middle::dep_graph::dep_node::default_dep_kind_debug;
16-
use rustc_middle::dep_graph::{DepContext, DepKind, DepNode, TaskDepsRef};
16+
use rustc_middle::dep_graph::{DepKind, DepNode, TaskDepsRef};
1717
use rustc_middle::ty::tls;
1818

1919
fn track_span_parent(def_id: rustc_span::def_id::LocalDefId) {

compiler/rustc_middle/src/dep_graph/dep_node.rs

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ use rustc_macros::{Decodable, Encodable};
6767
use rustc_query_system::ich::StableHashingContext;
6868
use rustc_span::Symbol;
6969

70-
use super::{DepContext, FingerprintStyle, SerializedDepNodeIndex};
70+
use super::{FingerprintStyle, SerializedDepNodeIndex};
7171
use crate::mir::mono::MonoItem;
7272
use crate::ty::TyCtxt;
7373

@@ -117,29 +117,25 @@ impl DepNode {
117117
/// Creates a new, parameterless DepNode. This method will assert
118118
/// that the DepNode corresponding to the given DepKind actually
119119
/// does not require any parameters.
120-
pub fn new_no_params<Tcx>(tcx: Tcx, kind: DepKind) -> DepNode
121-
where
122-
Tcx: super::DepContext,
123-
{
120+
pub fn new_no_params<'tcx>(tcx: TyCtxt<'tcx>, kind: DepKind) -> DepNode {
124121
debug_assert_eq!(tcx.fingerprint_style(kind), FingerprintStyle::Unit);
125122
DepNode { kind, hash: Fingerprint::ZERO.into() }
126123
}
127124

128-
pub fn construct<Tcx, Key>(tcx: Tcx, kind: DepKind, arg: &Key) -> DepNode
125+
pub fn construct<'tcx, Key>(tcx: TyCtxt<'tcx>, kind: DepKind, arg: &Key) -> DepNode
129126
where
130-
Tcx: super::DepContext,
131-
Key: DepNodeKey<Tcx>,
127+
Key: DepNodeKey<'tcx>,
132128
{
133129
let hash = arg.to_fingerprint(tcx);
134130
let dep_node = DepNode { kind, hash: hash.into() };
135131

136132
#[cfg(debug_assertions)]
137133
{
138134
if !tcx.fingerprint_style(kind).reconstructible()
139-
&& (tcx.sess().opts.unstable_opts.incremental_info
140-
|| tcx.sess().opts.unstable_opts.query_dep_graph)
135+
&& (tcx.sess.opts.unstable_opts.incremental_info
136+
|| tcx.sess.opts.unstable_opts.query_dep_graph)
141137
{
142-
tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
138+
tcx.dep_graph.register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
143139
}
144140
}
145141

@@ -149,10 +145,11 @@ impl DepNode {
149145
/// Construct a DepNode from the given DepKind and DefPathHash. This
150146
/// method will assert that the given DepKind actually requires a
151147
/// single DefId/DefPathHash parameter.
152-
pub fn from_def_path_hash<Tcx>(tcx: Tcx, def_path_hash: DefPathHash, kind: DepKind) -> Self
153-
where
154-
Tcx: super::DepContext,
155-
{
148+
pub fn from_def_path_hash<'tcx>(
149+
tcx: TyCtxt<'tcx>,
150+
def_path_hash: DefPathHash,
151+
kind: DepKind,
152+
) -> Self {
156153
debug_assert!(tcx.fingerprint_style(kind) == FingerprintStyle::DefPathHash);
157154
DepNode { kind, hash: def_path_hash.0.into() }
158155
}
@@ -172,26 +169,26 @@ impl fmt::Debug for DepNode {
172169
}
173170

174171
/// Trait for query keys as seen by dependency-node tracking.
175-
pub trait DepNodeKey<Tcx: DepContext>: fmt::Debug + Sized {
172+
pub trait DepNodeKey<'tcx>: fmt::Debug + Sized {
176173
fn fingerprint_style() -> FingerprintStyle;
177174

178175
/// This method turns a query key into an opaque `Fingerprint` to be used
179176
/// in `DepNode`.
180-
fn to_fingerprint(&self, _: Tcx) -> Fingerprint;
177+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint;
181178

182-
fn to_debug_str(&self, tcx: Tcx) -> String;
179+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String;
183180

184181
/// This method tries to recover the query key from the given `DepNode`,
185182
/// something which is needed when forcing `DepNode`s during red-green
186183
/// evaluation. The query system will only call this method if
187184
/// `fingerprint_style()` is not `FingerprintStyle::Opaque`.
188185
/// It is always valid to return `None` here, in which case incremental
189186
/// compilation will treat the query as having changed instead of forcing it.
190-
fn recover(tcx: Tcx, dep_node: &DepNode) -> Option<Self>;
187+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self>;
191188
}
192189

193190
// Blanket impl of `DepNodeKey`, which is specialized by other impls elsewhere.
194-
impl<Tcx: DepContext, T> DepNodeKey<Tcx> for T
191+
impl<'tcx, T> DepNodeKey<'tcx> for T
195192
where
196193
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
197194
{
@@ -201,7 +198,7 @@ where
201198
}
202199

203200
#[inline(always)]
204-
default fn to_fingerprint(&self, tcx: Tcx) -> Fingerprint {
201+
default fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
205202
tcx.with_stable_hashing_context(|mut hcx| {
206203
let mut hasher = StableHasher::new();
207204
self.hash_stable(&mut hcx, &mut hasher);
@@ -210,15 +207,15 @@ where
210207
}
211208

212209
#[inline(always)]
213-
default fn to_debug_str(&self, tcx: Tcx) -> String {
210+
default fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
214211
// Make sure to print dep node params with reduced queries since printing
215212
// may themselves call queries, which may lead to (possibly untracked!)
216213
// query cycles.
217214
tcx.with_reduced_queries(|| format!("{self:?}"))
218215
}
219216

220217
#[inline(always)]
221-
default fn recover(_: Tcx, _: &DepNode) -> Option<Self> {
218+
default fn recover(_: TyCtxt<'tcx>, _: &DepNode) -> Option<Self> {
222219
None
223220
}
224221
}
@@ -228,7 +225,7 @@ where
228225
/// Information is retrieved by indexing the `DEP_KINDS` array using the integer value
229226
/// of the `DepKind`. Overall, this allows to implement `DepContext` using this manual
230227
/// jump table instead of large matches.
231-
pub struct DepKindVTable<Tcx: DepContext> {
228+
pub struct DepKindVTable<'tcx> {
232229
/// Anonymous queries cannot be replayed from one compiler invocation to the next.
233230
/// When their result is needed, it is recomputed. They are useful for fine-grained
234231
/// dependency tracking, and caching within one compiler invocation.
@@ -279,11 +276,12 @@ pub struct DepKindVTable<Tcx: DepContext> {
279276
/// with kind `MirValidated`, we know that the GUID/fingerprint of the `DepNode`
280277
/// is actually a `DefPathHash`, and can therefore just look up the corresponding
281278
/// `DefId` in `tcx.def_path_hash_to_def_id`.
282-
pub force_from_dep_node:
283-
Option<fn(tcx: Tcx, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool>,
279+
pub force_from_dep_node: Option<
280+
fn(tcx: TyCtxt<'tcx>, dep_node: DepNode, prev_index: SerializedDepNodeIndex) -> bool,
281+
>,
284282

285283
/// Invoke a query to put the on-disk cached value in memory.
286-
pub try_load_from_on_disk_cache: Option<fn(Tcx, DepNode)>,
284+
pub try_load_from_on_disk_cache: Option<fn(TyCtxt<'tcx>, DepNode)>,
287285

288286
/// The name of this dep kind.
289287
pub name: &'static &'static str,

compiler/rustc_middle/src/dep_graph/dep_node_key.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalModDefId,
33
use rustc_hir::definitions::DefPathHash;
44
use rustc_hir::{HirId, ItemLocalId, OwnerId};
55

6-
use crate::dep_graph::{DepContext, DepNode, DepNodeKey, FingerprintStyle};
6+
use crate::dep_graph::{DepNode, DepNodeKey, FingerprintStyle};
77
use crate::ty::TyCtxt;
88

9-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for () {
9+
impl<'tcx> DepNodeKey<'tcx> for () {
1010
#[inline(always)]
1111
fn fingerprint_style() -> FingerprintStyle {
1212
FingerprintStyle::Unit
@@ -23,7 +23,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for () {
2323
}
2424
}
2525

26-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for DefId {
26+
impl<'tcx> DepNodeKey<'tcx> for DefId {
2727
#[inline(always)]
2828
fn fingerprint_style() -> FingerprintStyle {
2929
FingerprintStyle::DefPathHash
@@ -45,7 +45,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for DefId {
4545
}
4646
}
4747

48-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalDefId {
48+
impl<'tcx> DepNodeKey<'tcx> for LocalDefId {
4949
#[inline(always)]
5050
fn fingerprint_style() -> FingerprintStyle {
5151
FingerprintStyle::DefPathHash
@@ -67,7 +67,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalDefId {
6767
}
6868
}
6969

70-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for OwnerId {
70+
impl<'tcx> DepNodeKey<'tcx> for OwnerId {
7171
#[inline(always)]
7272
fn fingerprint_style() -> FingerprintStyle {
7373
FingerprintStyle::DefPathHash
@@ -89,7 +89,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for OwnerId {
8989
}
9090
}
9191

92-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for CrateNum {
92+
impl<'tcx> DepNodeKey<'tcx> for CrateNum {
9393
#[inline(always)]
9494
fn fingerprint_style() -> FingerprintStyle {
9595
FingerprintStyle::DefPathHash
@@ -112,7 +112,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for CrateNum {
112112
}
113113
}
114114

115-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for (DefId, DefId) {
115+
impl<'tcx> DepNodeKey<'tcx> for (DefId, DefId) {
116116
#[inline(always)]
117117
fn fingerprint_style() -> FingerprintStyle {
118118
FingerprintStyle::Opaque
@@ -139,7 +139,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for (DefId, DefId) {
139139
}
140140
}
141141

142-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for HirId {
142+
impl<'tcx> DepNodeKey<'tcx> for HirId {
143143
#[inline(always)]
144144
fn fingerprint_style() -> FingerprintStyle {
145145
FingerprintStyle::HirId
@@ -182,7 +182,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for HirId {
182182
}
183183
}
184184

185-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for ModDefId {
185+
impl<'tcx> DepNodeKey<'tcx> for ModDefId {
186186
#[inline(always)]
187187
fn fingerprint_style() -> FingerprintStyle {
188188
FingerprintStyle::DefPathHash
@@ -204,7 +204,7 @@ impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for ModDefId {
204204
}
205205
}
206206

207-
impl<'tcx> DepNodeKey<TyCtxt<'tcx>> for LocalModDefId {
207+
impl<'tcx> DepNodeKey<'tcx> for LocalModDefId {
208208
#[inline(always)]
209209
fn fingerprint_style() -> FingerprintStyle {
210210
FingerprintStyle::DefPathHash

compiler/rustc_middle/src/dep_graph/graph.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use {super::debug::EdgeFilter, std::env};
2525

2626
use super::query::DepGraphQuery;
2727
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
28-
use super::{DepContext, DepKind, DepNode, DepsType, HasDepContext, WorkProductId};
28+
use super::{DepKind, DepNode, DepsType, HasDepContext, WorkProductId};
2929
use crate::dep_graph::edges::EdgesVec;
3030
use crate::ty::TyCtxt;
3131
use crate::verify_ich::incremental_verify_ich;
@@ -62,7 +62,7 @@ impl From<DepNodeIndex> for QueryInvocationId {
6262
}
6363
}
6464

65-
pub struct MarkFrame<'a> {
65+
pub(crate) struct MarkFrame<'a> {
6666
index: SerializedDepNodeIndex,
6767
parent: Option<&'a MarkFrame<'a>>,
6868
}
@@ -252,7 +252,7 @@ impl DepGraph {
252252
}
253253

254254
#[inline(always)]
255-
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
255+
pub fn with_task<'tcx, Ctxt: HasDepContext<'tcx>, A: Debug, R>(
256256
&self,
257257
key: DepNode,
258258
cx: Ctxt,
@@ -266,9 +266,9 @@ impl DepGraph {
266266
}
267267
}
268268

269-
pub fn with_anon_task<Tcx: DepContext, OP, R>(
269+
pub fn with_anon_task<'tcx, OP, R>(
270270
&self,
271-
cx: Tcx,
271+
cx: TyCtxt<'tcx>,
272272
dep_kind: DepKind,
273273
op: OP,
274274
) -> (R, DepNodeIndex)
@@ -315,7 +315,7 @@ impl DepGraphData {
315315
///
316316
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/queries/incremental-compilation.html
317317
#[inline(always)]
318-
pub fn with_task<Ctxt: HasDepContext, A: Debug, R>(
318+
pub fn with_task<'tcx, Ctxt: HasDepContext<'tcx>, A: Debug, R>(
319319
&self,
320320
key: DepNode,
321321
cx: Ctxt,
@@ -329,7 +329,7 @@ impl DepGraphData {
329329
// 2. Two distinct query keys get mapped to the same `DepNode`
330330
// (see for example #48923).
331331
self.assert_dep_node_not_yet_allocated_in_current_session(
332-
cx.dep_context().sess(),
332+
cx.dep_context().sess,
333333
&key,
334334
|| {
335335
format!(
@@ -352,8 +352,8 @@ impl DepGraphData {
352352
(with_deps(TaskDepsRef::Allow(&task_deps)), task_deps.into_inner().reads)
353353
};
354354

355-
let dcx = cx.dep_context();
356-
let dep_node_index = self.hash_result_and_alloc_node(dcx, key, edges, &result, hash_result);
355+
let dep_node_index =
356+
self.hash_result_and_alloc_node(cx.dep_context(), key, edges, &result, hash_result);
357357

358358
(result, dep_node_index)
359359
}
@@ -369,9 +369,9 @@ impl DepGraphData {
369369
/// FIXME: This could perhaps return a `WithDepNode` to ensure that the
370370
/// user of this function actually performs the read; we'll have to see
371371
/// how to make that work with `anon` in `execute_job_incr`, though.
372-
pub fn with_anon_task_inner<Tcx: DepContext, OP, R>(
372+
pub fn with_anon_task_inner<'tcx, OP, R>(
373373
&self,
374-
cx: Tcx,
374+
cx: TyCtxt<'tcx>,
375375
dep_kind: DepKind,
376376
op: OP,
377377
) -> (R, DepNodeIndex)
@@ -438,17 +438,17 @@ impl DepGraphData {
438438
}
439439

440440
/// Intern the new `DepNode` with the dependencies up-to-now.
441-
fn hash_result_and_alloc_node<Ctxt: DepContext, R>(
441+
fn hash_result_and_alloc_node<'tcx, R>(
442442
&self,
443-
cx: &Ctxt,
443+
tcx: TyCtxt<'tcx>,
444444
node: DepNode,
445445
edges: EdgesVec,
446446
result: &R,
447447
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
448448
) -> DepNodeIndex {
449-
let hashing_timer = cx.profiler().incr_result_hashing();
449+
let hashing_timer = tcx.prof.incr_result_hashing();
450450
let current_fingerprint = hash_result.map(|hash_result| {
451-
cx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
451+
tcx.with_stable_hashing_context(|mut hcx| hash_result(&mut hcx, result))
452452
});
453453
let dep_node_index = self.alloc_and_color_node(node, edges, current_fingerprint);
454454
hashing_timer.finish_with_query_invocation_id(dep_node_index.into());
@@ -553,10 +553,10 @@ impl DepGraph {
553553
/// FIXME: If the code is changed enough for this node to be marked before requiring the
554554
/// caller's node, we suppose that those changes will be enough to mark this node red and
555555
/// force a recomputation using the "normal" way.
556-
pub fn with_feed_task<Ctxt: DepContext, R>(
556+
pub fn with_feed_task<'tcx, R>(
557557
&self,
558558
node: DepNode,
559-
cx: Ctxt,
559+
tcx: TyCtxt<'tcx>,
560560
result: &R,
561561
hash_result: Option<fn(&mut StableHashingContext<'_>, &R) -> Fingerprint>,
562562
format_value_fn: fn(&R) -> String,
@@ -572,7 +572,7 @@ impl DepGraph {
572572
let dep_node_index = data.colors.current(prev_index);
573573
if let Some(dep_node_index) = dep_node_index {
574574
incremental_verify_ich(
575-
cx,
575+
tcx,
576576
data,
577577
result,
578578
prev_index,
@@ -605,7 +605,7 @@ impl DepGraph {
605605
}
606606
});
607607

608-
data.hash_result_and_alloc_node(&cx, node, edges, result, hash_result)
608+
data.hash_result_and_alloc_node(tcx, node, edges, result, hash_result)
609609
} else {
610610
// Incremental compilation is turned off. We just execute the task
611611
// without tracking. We still provide a dep-node index that uniquely
@@ -1051,8 +1051,8 @@ impl DepGraph {
10511051
///
10521052
/// This method will only load queries that will end up in the disk cache.
10531053
/// Other queries will not be executed.
1054-
pub fn exec_cache_promotions<Tcx: DepContext>(&self, tcx: Tcx) {
1055-
let _prof_timer = tcx.profiler().generic_activity("incr_comp_query_cache_promotion");
1054+
pub fn exec_cache_promotions<'tcx>(&self, tcx: TyCtxt<'tcx>) {
1055+
let _prof_timer = tcx.prof.generic_activity("incr_comp_query_cache_promotion");
10561056

10571057
let data = self.data.as_ref().unwrap();
10581058
for prev_index in data.colors.values.indices() {

0 commit comments

Comments
 (0)