Skip to content

Commit fedd778

Browse files
committed
Access StableHashingContext in rustc_query_system.
1 parent 471cb5c commit fedd778

File tree

6 files changed

+17
-25
lines changed

6 files changed

+17
-25
lines changed

compiler/rustc_middle/src/dep_graph/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,9 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
9090

9191
impl<'tcx> DepContext for TyCtxt<'tcx> {
9292
type DepKind = DepKind;
93-
type StableHashingContext = StableHashingContext<'tcx>;
9493

9594
#[inline]
96-
fn create_stable_hashing_context(&self) -> Self::StableHashingContext {
95+
fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
9796
TyCtxt::create_stable_hashing_context(*self)
9897
}
9998

compiler/rustc_query_impl/src/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
3636

3737
impl HasDepContext for QueryCtxt<'tcx> {
3838
type DepKind = rustc_middle::dep_graph::DepKind;
39-
type StableHashingContext = rustc_query_system::ich::StableHashingContext<'tcx>;
4039
type DepContext = TyCtxt<'tcx>;
4140

4241
#[inline]

compiler/rustc_query_system/src/dep_graph/dep_node.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
//! lost during fingerprint computation.
4444
4545
use super::{DepContext, DepKind};
46+
use crate::ich::StableHashingContext;
4647

4748
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
4849
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
49-
5050
use std::fmt;
5151
use std::hash::Hash;
5252

@@ -119,7 +119,7 @@ pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
119119

120120
impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T
121121
where
122-
T: HashStable<Ctxt::StableHashingContext> + fmt::Debug,
122+
T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
123123
{
124124
#[inline]
125125
default fn can_reconstruct_query_key() -> bool {

compiler/rustc_query_system/src/dep_graph/graph.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use parking_lot::Mutex;
12
use rustc_data_structures::fingerprint::Fingerprint;
23
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
34
use rustc_data_structures::profiling::{EventId, QueryInvocationId, SelfProfilerRef};
@@ -7,8 +8,6 @@ use rustc_data_structures::steal::Steal;
78
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
89
use rustc_index::vec::IndexVec;
910
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
10-
11-
use parking_lot::Mutex;
1211
use smallvec::{smallvec, SmallVec};
1312
use std::collections::hash_map::Entry;
1413
use std::fmt::Debug;
@@ -19,6 +18,7 @@ use std::sync::atomic::Ordering::Relaxed;
1918
use super::query::DepGraphQuery;
2019
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
2120
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
21+
use crate::ich::StableHashingContext;
2222
use crate::query::{QueryContext, QuerySideEffects};
2323

2424
#[cfg(debug_assertions)]
@@ -96,9 +96,9 @@ struct DepGraphData<K: DepKind> {
9696
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
9797
}
9898

99-
pub fn hash_result<HashCtxt, R>(hcx: &mut HashCtxt, result: &R) -> Option<Fingerprint>
99+
pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Option<Fingerprint>
100100
where
101-
R: HashStable<HashCtxt>,
101+
R: for<'a> HashStable<StableHashingContext<'a>>,
102102
{
103103
let mut stable_hasher = StableHasher::new();
104104
result.hash_stable(hcx, &mut stable_hasher);
@@ -215,7 +215,7 @@ impl<K: DepKind> DepGraph<K> {
215215
cx: Ctxt,
216216
arg: A,
217217
task: fn(Ctxt, A) -> R,
218-
hash_result: fn(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
218+
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
219219
) -> (R, DepNodeIndex) {
220220
if self.is_fully_enabled() {
221221
self.with_task_impl(key, cx, arg, task, hash_result)
@@ -234,7 +234,7 @@ impl<K: DepKind> DepGraph<K> {
234234
cx: Ctxt,
235235
arg: A,
236236
task: fn(Ctxt, A) -> R,
237-
hash_result: fn(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
237+
hash_result: fn(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
238238
) -> (R, DepNodeIndex) {
239239
// This function is only called when the graph is enabled.
240240
let data = self.data.as_ref().unwrap();

compiler/rustc_query_system/src/dep_graph/mod.rs

+3-8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, Wor
99
pub use query::DepGraphQuery;
1010
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
1111

12+
use crate::ich::StableHashingContext;
1213
use rustc_data_structures::profiling::SelfProfilerRef;
1314
use rustc_data_structures::sync::Lock;
1415
use rustc_serialize::{opaque::FileEncoder, Encodable};
@@ -19,10 +20,9 @@ use std::hash::Hash;
1920

2021
pub trait DepContext: Copy {
2122
type DepKind: self::DepKind;
22-
type StableHashingContext;
2323

2424
/// Create a hashing context for hashing new results.
25-
fn create_stable_hashing_context(&self) -> Self::StableHashingContext;
25+
fn create_stable_hashing_context(&self) -> StableHashingContext<'_>;
2626

2727
/// Access the DepGraph.
2828
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
@@ -36,18 +36,13 @@ pub trait DepContext: Copy {
3636

3737
pub trait HasDepContext: Copy {
3838
type DepKind: self::DepKind;
39-
type StableHashingContext;
40-
type DepContext: self::DepContext<
41-
DepKind = Self::DepKind,
42-
StableHashingContext = Self::StableHashingContext,
43-
>;
39+
type DepContext: self::DepContext<DepKind = Self::DepKind>;
4440

4541
fn dep_context(&self) -> &Self::DepContext;
4642
}
4743

4844
impl<T: DepContext> HasDepContext for T {
4945
type DepKind = T::DepKind;
50-
type StableHashingContext = T::StableHashingContext;
5146
type DepContext = Self;
5247

5348
fn dep_context(&self) -> &Self::DepContext {

compiler/rustc_query_system/src/query/config.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use crate::dep_graph::DepNode;
44
use crate::dep_graph::SerializedDepNodeIndex;
5+
use crate::ich::StableHashingContext;
56
use crate::query::caches::QueryCache;
67
use crate::query::{QueryCacheStore, QueryContext, QueryState};
78

@@ -23,7 +24,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
2324
pub dep_kind: CTX::DepKind,
2425
pub eval_always: bool,
2526

26-
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>,
27+
pub hash_result: fn(&mut StableHashingContext<'_>, &V) -> Option<Fingerprint>,
2728
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
2829
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
2930
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
@@ -39,7 +40,7 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
3940

4041
pub(crate) fn hash_result(
4142
&self,
42-
hcx: &mut CTX::StableHashingContext,
43+
hcx: &mut StableHashingContext<'_>,
4344
value: &V,
4445
) -> Option<Fingerprint> {
4546
(self.hash_result)(hcx, value)
@@ -74,10 +75,8 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
7475
// Don't use this method to compute query results, instead use the methods on TyCtxt
7576
fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value;
7677

77-
fn hash_result(
78-
hcx: &mut CTX::StableHashingContext,
79-
result: &Self::Value,
80-
) -> Option<Fingerprint>;
78+
fn hash_result(hcx: &mut StableHashingContext<'_>, result: &Self::Value)
79+
-> Option<Fingerprint>;
8180

8281
fn handle_cycle_error(tcx: CTX, diag: DiagnosticBuilder<'_>) -> Self::Value;
8382
}

0 commit comments

Comments
 (0)