Skip to content

Commit b6033fc

Browse files
committed
Retire DepGraphSafe and HashStableContext.
1 parent 228ca8e commit b6033fc

File tree

9 files changed

+29
-151
lines changed

9 files changed

+29
-151
lines changed

src/librustc/dep_graph/mod.rs

-17
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use rustc_errors::Diagnostic;
88
use rustc_hir::def_id::DefId;
99

1010
mod dep_node;
11-
mod safe;
1211

1312
pub(crate) use rustc_query_system::dep_graph::DepNodeParams;
1413
pub use rustc_query_system::dep_graph::{
@@ -17,8 +16,6 @@ pub use rustc_query_system::dep_graph::{
1716
};
1817

1918
pub use dep_node::{label_strs, DepConstructor, DepKind, DepNode, DepNodeExt};
20-
pub use safe::AssertDepGraphSafe;
21-
pub use safe::DepGraphSafe;
2219

2320
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
2421
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
@@ -189,17 +186,3 @@ impl rustc_query_system::HashStableContext for StableHashingContext<'_> {
189186
self.sess().opts.debugging_opts.dep_tasks
190187
}
191188
}
192-
193-
impl rustc_query_system::HashStableContextProvider<StableHashingContext<'tcx>> for TyCtxt<'tcx> {
194-
fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> {
195-
self.create_stable_hashing_context()
196-
}
197-
}
198-
199-
impl rustc_query_system::HashStableContextProvider<StableHashingContext<'a>>
200-
for StableHashingContext<'a>
201-
{
202-
fn get_stable_hashing_context(&self) -> Self {
203-
self.clone()
204-
}
205-
}

src/librustc/dep_graph/safe.rs

-9
This file was deleted.

src/librustc/ich/hcx.rs

-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
194194
}
195195
}
196196

197-
impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}
198-
199197
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
200198
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
201199
panic!("Node IDs should not appear in incremental state");

src/librustc_codegen_llvm/context.rs

-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::type_::Type;
77
use crate::value::Value;
88

99
use rustc::bug;
10-
use rustc::dep_graph::DepGraphSafe;
1110
use rustc::mir::mono::CodegenUnit;
1211
use rustc::ty::layout::{
1312
HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx,
@@ -90,8 +89,6 @@ pub struct CodegenCx<'ll, 'tcx> {
9089
local_gen_sym_counter: Cell<usize>,
9190
}
9291

93-
impl<'ll, 'tcx> DepGraphSafe for CodegenCx<'ll, 'tcx> {}
94-
9592
pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
9693
let reloc_model_arg = match sess.opts.cg.relocation_model {
9794
Some(ref s) => &s[..],

src/librustc_query_system/dep_graph/graph.rs

+17-30
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ use std::sync::atomic::Ordering::Relaxed;
2020
use super::debug::EdgeFilter;
2121
use super::prev::PreviousDepGraph;
2222
use super::query::DepGraphQuery;
23-
use super::safe::DepGraphSafe;
2423
use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
2524
use super::{DepContext, DepKind, DepNode, WorkProductId};
26-
use crate::{HashStableContext, HashStableContextProvider};
25+
use crate::HashStableContext;
2726

2827
#[derive(Clone)]
2928
pub struct DepGraph<K: DepKind> {
@@ -191,18 +190,14 @@ impl<K: DepKind> DepGraph<K> {
191190
/// `arg` parameter.
192191
///
193192
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html
194-
pub fn with_task<H, C, A, R>(
193+
pub fn with_task<Ctxt: DepContext<DepKind = K>, A, R>(
195194
&self,
196195
key: DepNode<K>,
197-
cx: C,
196+
cx: Ctxt,
198197
arg: A,
199-
task: fn(C, A) -> R,
200-
hash_result: impl FnOnce(&mut H, &R) -> Option<Fingerprint>,
201-
) -> (R, DepNodeIndex)
202-
where
203-
C: DepGraphSafe + HashStableContextProvider<H>,
204-
H: HashStableContext,
205-
{
198+
task: fn(Ctxt, A) -> R,
199+
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
200+
) -> (R, DepNodeIndex) {
206201
self.with_task_impl(
207202
key,
208203
cx,
@@ -223,26 +218,22 @@ impl<K: DepKind> DepGraph<K> {
223218
)
224219
}
225220

226-
fn with_task_impl<H, C, A, R>(
221+
fn with_task_impl<Ctxt: DepContext<DepKind = K>, A, R>(
227222
&self,
228223
key: DepNode<K>,
229-
cx: C,
224+
cx: Ctxt,
230225
arg: A,
231226
no_tcx: bool,
232-
task: fn(C, A) -> R,
227+
task: fn(Ctxt, A) -> R,
233228
create_task: fn(DepNode<K>) -> Option<TaskDeps<K>>,
234229
finish_task_and_alloc_depnode: fn(
235230
&CurrentDepGraph<K>,
236231
DepNode<K>,
237232
Fingerprint,
238233
Option<TaskDeps<K>>,
239234
) -> DepNodeIndex,
240-
hash_result: impl FnOnce(&mut H, &R) -> Option<Fingerprint>,
241-
) -> (R, DepNodeIndex)
242-
where
243-
C: DepGraphSafe + HashStableContextProvider<H>,
244-
H: HashStableContext,
245-
{
235+
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
236+
) -> (R, DepNodeIndex) {
246237
if let Some(ref data) = self.data {
247238
let task_deps = create_task(key).map(Lock::new);
248239

@@ -251,7 +242,7 @@ impl<K: DepKind> DepGraph<K> {
251242
// anyway so that
252243
// - we make sure that the infrastructure works and
253244
// - we can get an idea of the runtime cost.
254-
let mut hcx = cx.get_stable_hashing_context();
245+
let mut hcx = cx.create_stable_hashing_context();
255246

256247
let result = if no_tcx {
257248
task(cx, arg)
@@ -335,18 +326,14 @@ impl<K: DepKind> DepGraph<K> {
335326

336327
/// Executes something within an "eval-always" task which is a task
337328
/// that runs whenever anything changes.
338-
pub fn with_eval_always_task<H, C, A, R>(
329+
pub fn with_eval_always_task<Ctxt: DepContext<DepKind = K>, A, R>(
339330
&self,
340331
key: DepNode<K>,
341-
cx: C,
332+
cx: Ctxt,
342333
arg: A,
343-
task: fn(C, A) -> R,
344-
hash_result: impl FnOnce(&mut H, &R) -> Option<Fingerprint>,
345-
) -> (R, DepNodeIndex)
346-
where
347-
C: DepGraphSafe + HashStableContextProvider<H>,
348-
H: HashStableContext,
349-
{
334+
task: fn(Ctxt, A) -> R,
335+
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
336+
) -> (R, DepNodeIndex) {
350337
self.with_task_impl(
351338
key,
352339
cx,

src/librustc_query_system/dep_graph/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@ mod dep_node;
33
mod graph;
44
mod prev;
55
mod query;
6-
mod safe;
76
mod serialized;
87

98
pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
109
pub use graph::WorkProductFileKind;
1110
pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, WorkProduct};
1211
pub use prev::PreviousDepGraph;
1312
pub use query::DepGraphQuery;
14-
pub use safe::AssertDepGraphSafe;
15-
pub use safe::DepGraphSafe;
1613
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
1714

1815
use rustc_data_structures::profiling::SelfProfilerRef;
@@ -23,7 +20,7 @@ use rustc_errors::Diagnostic;
2320
use std::fmt;
2421
use std::hash::Hash;
2522

26-
pub trait DepContext: Copy + DepGraphSafe {
23+
pub trait DepContext: Copy {
2724
type DepKind: self::DepKind;
2825
type StableHashingContext: crate::HashStableContext;
2926

src/librustc_query_system/dep_graph/safe.rs

-51
This file was deleted.

src/librustc_query_system/lib.rs

-17
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,3 @@ pub mod query;
1919
pub trait HashStableContext {
2020
fn debug_dep_tasks(&self) -> bool;
2121
}
22-
23-
/// Something that can provide a stable hashing context.
24-
pub trait HashStableContextProvider<Ctxt> {
25-
fn get_stable_hashing_context(&self) -> Ctxt;
26-
}
27-
28-
impl<Ctxt, T: HashStableContextProvider<Ctxt>> HashStableContextProvider<Ctxt> for &T {
29-
fn get_stable_hashing_context(&self) -> Ctxt {
30-
(**self).get_stable_hashing_context()
31-
}
32-
}
33-
34-
impl<Ctxt, T: HashStableContextProvider<Ctxt>> HashStableContextProvider<Ctxt> for &mut T {
35-
fn get_stable_hashing_context(&self) -> Ctxt {
36-
(**self).get_stable_hashing_context()
37-
}
38-
}

src/librustc_query_system/query/plumbing.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
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::{DepContext, DepKind, DepNode};
5+
use crate::dep_graph::{DepKind, DepNode};
66
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
77
use crate::query::caches::QueryCache;
88
use crate::query::config::{QueryContext, QueryDescription};
99
use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
10-
use crate::HashStableContextProvider;
1110

1211
#[cfg(not(parallel_compiler))]
1312
use rustc_data_structures::cold_path;
@@ -382,17 +381,15 @@ where
382381
}
383382

384383
#[inline(always)]
385-
fn try_execute_query<Q, CTX, K>(
384+
fn try_execute_query<Q, CTX>(
386385
tcx: CTX,
387386
span: Span,
388387
key: Q::Key,
389388
lookup: QueryLookup<'_, CTX, Q::Key, <Q::Cache as QueryCache<CTX>>::Sharded>,
390389
) -> Q::Value
391390
where
392391
Q: QueryDescription<CTX>,
393-
CTX: QueryContext<DepKind = K>,
394-
CTX: HashStableContextProvider<<CTX as DepContext>::StableHashingContext>,
395-
K: DepKind,
392+
CTX: QueryContext,
396393
{
397394
let job = match JobOwner::try_start::<Q, _>(tcx, span, &key, lookup) {
398395
TryGetJob::NotYetStarted(job) => job,
@@ -408,7 +405,7 @@ where
408405
// expensive for some `DepKind`s.
409406
if !tcx.dep_graph().is_fully_enabled() {
410407
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
411-
return force_query_with_job::<Q, _, _>(tcx, key, job, null_dep_node).0;
408+
return force_query_with_job::<Q, _>(tcx, key, job, null_dep_node).0;
412409
}
413410

414411
if Q::ANON {
@@ -460,7 +457,7 @@ where
460457
}
461458
}
462459

463-
let (result, dep_node_index) = force_query_with_job::<Q, _, _>(tcx, key, job, dep_node);
460+
let (result, dep_node_index) = force_query_with_job::<Q, _>(tcx, key, job, dep_node);
464461
tcx.dep_graph().read_index(dep_node_index);
465462
result
466463
}
@@ -554,17 +551,15 @@ fn incremental_verify_ich<Q, CTX>(
554551
}
555552

556553
#[inline(always)]
557-
fn force_query_with_job<Q, CTX, K>(
554+
fn force_query_with_job<Q, CTX>(
558555
tcx: CTX,
559556
key: Q::Key,
560557
job: JobOwner<'_, CTX, Q::Cache>,
561558
dep_node: DepNode<CTX::DepKind>,
562559
) -> (Q::Value, DepNodeIndex)
563560
where
564561
Q: QueryDescription<CTX>,
565-
CTX: QueryContext<DepKind = K>,
566-
CTX: HashStableContextProvider<<CTX as DepContext>::StableHashingContext>,
567-
K: DepKind,
562+
CTX: QueryContext,
568563
{
569564
// If the following assertion triggers, it can have two reasons:
570565
// 1. Something is wrong with DepNode creation, either here or
@@ -631,11 +626,9 @@ pub trait QueryGetter: QueryContext {
631626
);
632627
}
633628

634-
impl<CTX, K> QueryGetter for CTX
629+
impl<CTX> QueryGetter for CTX
635630
where
636-
CTX: QueryContext<DepKind = K>,
637-
CTX: HashStableContextProvider<<CTX as DepContext>::StableHashingContext>,
638-
K: DepKind,
631+
CTX: QueryContext,
639632
{
640633
#[inline(never)]
641634
fn get_query<Q: QueryDescription<Self>>(self, span: Span, key: Q::Key) -> Q::Value {
@@ -649,7 +642,7 @@ where
649642
self.dep_graph().read_index(index);
650643
value.clone()
651644
},
652-
|key, lookup| try_execute_query::<Q, _, _>(self, span, key, lookup),
645+
|key, lookup| try_execute_query::<Q, _>(self, span, key, lookup),
653646
)
654647
}
655648

@@ -710,7 +703,7 @@ where
710703
#[cfg(parallel_compiler)]
711704
TryGetJob::JobCompleted(_) => return,
712705
};
713-
force_query_with_job::<Q, _, _>(self, key, job, dep_node);
706+
force_query_with_job::<Q, _>(self, key, job, dep_node);
714707
},
715708
);
716709
}

0 commit comments

Comments
 (0)