Access StableHashingContext in rustc_query_system.

This commit is contained in:
Camille GILLOT 2021-09-26 01:40:17 +02:00
parent 471cb5c149
commit fedd7785fe
6 changed files with 17 additions and 25 deletions

View file

@ -90,10 +90,9 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
impl<'tcx> DepContext for TyCtxt<'tcx> { impl<'tcx> DepContext for TyCtxt<'tcx> {
type DepKind = DepKind; type DepKind = DepKind;
type StableHashingContext = StableHashingContext<'tcx>;
#[inline] #[inline]
fn create_stable_hashing_context(&self) -> Self::StableHashingContext { fn create_stable_hashing_context(&self) -> StableHashingContext<'_> {
TyCtxt::create_stable_hashing_context(*self) TyCtxt::create_stable_hashing_context(*self)
} }

View file

@ -36,7 +36,6 @@ impl<'tcx> std::ops::Deref for QueryCtxt<'tcx> {
impl HasDepContext for QueryCtxt<'tcx> { impl HasDepContext for QueryCtxt<'tcx> {
type DepKind = rustc_middle::dep_graph::DepKind; type DepKind = rustc_middle::dep_graph::DepKind;
type StableHashingContext = rustc_query_system::ich::StableHashingContext<'tcx>;
type DepContext = TyCtxt<'tcx>; type DepContext = TyCtxt<'tcx>;
#[inline] #[inline]

View file

@ -43,10 +43,10 @@
//! lost during fingerprint computation. //! lost during fingerprint computation.
use super::{DepContext, DepKind}; use super::{DepContext, DepKind};
use crate::ich::StableHashingContext;
use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint}; use rustc_data_structures::fingerprint::{Fingerprint, PackedFingerprint};
use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use std::fmt; use std::fmt;
use std::hash::Hash; use std::hash::Hash;
@ -119,7 +119,7 @@ pub trait DepNodeParams<Ctxt: DepContext>: fmt::Debug + Sized {
impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T impl<Ctxt: DepContext, T> DepNodeParams<Ctxt> for T
where where
T: HashStable<Ctxt::StableHashingContext> + fmt::Debug, T: for<'a> HashStable<StableHashingContext<'a>> + fmt::Debug,
{ {
#[inline] #[inline]
default fn can_reconstruct_query_key() -> bool { default fn can_reconstruct_query_key() -> bool {

View file

@ -1,3 +1,4 @@
use parking_lot::Mutex;
use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::profiling::{EventId, QueryInvocationId, SelfProfilerRef}; use rustc_data_structures::profiling::{EventId, QueryInvocationId, SelfProfilerRef};
@ -7,8 +8,6 @@ use rustc_data_structures::steal::Steal;
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering}; use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
use rustc_index::vec::IndexVec; use rustc_index::vec::IndexVec;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder}; use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
use parking_lot::Mutex;
use smallvec::{smallvec, SmallVec}; use smallvec::{smallvec, SmallVec};
use std::collections::hash_map::Entry; use std::collections::hash_map::Entry;
use std::fmt::Debug; use std::fmt::Debug;
@ -19,6 +18,7 @@ use std::sync::atomic::Ordering::Relaxed;
use super::query::DepGraphQuery; use super::query::DepGraphQuery;
use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex}; use super::serialized::{GraphEncoder, SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId}; use super::{DepContext, DepKind, DepNode, HasDepContext, WorkProductId};
use crate::ich::StableHashingContext;
use crate::query::{QueryContext, QuerySideEffects}; use crate::query::{QueryContext, QuerySideEffects};
#[cfg(debug_assertions)] #[cfg(debug_assertions)]
@ -96,9 +96,9 @@ struct DepGraphData<K: DepKind> {
dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>, dep_node_debug: Lock<FxHashMap<DepNode<K>, String>>,
} }
pub fn hash_result<HashCtxt, R>(hcx: &mut HashCtxt, result: &R) -> Option<Fingerprint> pub fn hash_result<R>(hcx: &mut StableHashingContext<'_>, result: &R) -> Option<Fingerprint>
where where
R: HashStable<HashCtxt>, R: for<'a> HashStable<StableHashingContext<'a>>,
{ {
let mut stable_hasher = StableHasher::new(); let mut stable_hasher = StableHasher::new();
result.hash_stable(hcx, &mut stable_hasher); result.hash_stable(hcx, &mut stable_hasher);
@ -215,7 +215,7 @@ impl<K: DepKind> DepGraph<K> {
cx: Ctxt, cx: Ctxt,
arg: A, arg: A,
task: fn(Ctxt, A) -> R, task: fn(Ctxt, A) -> R,
hash_result: fn(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>, hash_result: fn(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
) -> (R, DepNodeIndex) { ) -> (R, DepNodeIndex) {
if self.is_fully_enabled() { if self.is_fully_enabled() {
self.with_task_impl(key, cx, arg, task, hash_result) self.with_task_impl(key, cx, arg, task, hash_result)
@ -234,7 +234,7 @@ impl<K: DepKind> DepGraph<K> {
cx: Ctxt, cx: Ctxt,
arg: A, arg: A,
task: fn(Ctxt, A) -> R, task: fn(Ctxt, A) -> R,
hash_result: fn(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>, hash_result: fn(&mut StableHashingContext<'_>, &R) -> Option<Fingerprint>,
) -> (R, DepNodeIndex) { ) -> (R, DepNodeIndex) {
// This function is only called when the graph is enabled. // This function is only called when the graph is enabled.
let data = self.data.as_ref().unwrap(); let data = self.data.as_ref().unwrap();

View file

@ -9,6 +9,7 @@ pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, Wor
pub use query::DepGraphQuery; pub use query::DepGraphQuery;
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex}; pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
use crate::ich::StableHashingContext;
use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lock; use rustc_data_structures::sync::Lock;
use rustc_serialize::{opaque::FileEncoder, Encodable}; use rustc_serialize::{opaque::FileEncoder, Encodable};
@ -19,10 +20,9 @@ use std::hash::Hash;
pub trait DepContext: Copy { pub trait DepContext: Copy {
type DepKind: self::DepKind; type DepKind: self::DepKind;
type StableHashingContext;
/// Create a hashing context for hashing new results. /// Create a hashing context for hashing new results.
fn create_stable_hashing_context(&self) -> Self::StableHashingContext; fn create_stable_hashing_context(&self) -> StableHashingContext<'_>;
/// Access the DepGraph. /// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>; fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
@ -36,18 +36,13 @@ pub trait DepContext: Copy {
pub trait HasDepContext: Copy { pub trait HasDepContext: Copy {
type DepKind: self::DepKind; type DepKind: self::DepKind;
type StableHashingContext; type DepContext: self::DepContext<DepKind = Self::DepKind>;
type DepContext: self::DepContext<
DepKind = Self::DepKind,
StableHashingContext = Self::StableHashingContext,
>;
fn dep_context(&self) -> &Self::DepContext; fn dep_context(&self) -> &Self::DepContext;
} }
impl<T: DepContext> HasDepContext for T { impl<T: DepContext> HasDepContext for T {
type DepKind = T::DepKind; type DepKind = T::DepKind;
type StableHashingContext = T::StableHashingContext;
type DepContext = Self; type DepContext = Self;
fn dep_context(&self) -> &Self::DepContext { fn dep_context(&self) -> &Self::DepContext {

View file

@ -2,6 +2,7 @@
use crate::dep_graph::DepNode; use crate::dep_graph::DepNode;
use crate::dep_graph::SerializedDepNodeIndex; use crate::dep_graph::SerializedDepNodeIndex;
use crate::ich::StableHashingContext;
use crate::query::caches::QueryCache; use crate::query::caches::QueryCache;
use crate::query::{QueryCacheStore, QueryContext, QueryState}; use crate::query::{QueryCacheStore, QueryContext, QueryState};
@ -23,7 +24,7 @@ pub(crate) struct QueryVtable<CTX: QueryContext, K, V> {
pub dep_kind: CTX::DepKind, pub dep_kind: CTX::DepKind,
pub eval_always: bool, pub eval_always: bool,
pub hash_result: fn(&mut CTX::StableHashingContext, &V) -> Option<Fingerprint>, pub hash_result: fn(&mut StableHashingContext<'_>, &V) -> Option<Fingerprint>,
pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V, pub handle_cycle_error: fn(CTX, DiagnosticBuilder<'_>) -> V,
pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool, pub cache_on_disk: fn(CTX, &K, Option<&V>) -> bool,
pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>, pub try_load_from_disk: fn(CTX, SerializedDepNodeIndex) -> Option<V>,
@ -39,7 +40,7 @@ impl<CTX: QueryContext, K, V> QueryVtable<CTX, K, V> {
pub(crate) fn hash_result( pub(crate) fn hash_result(
&self, &self,
hcx: &mut CTX::StableHashingContext, hcx: &mut StableHashingContext<'_>,
value: &V, value: &V,
) -> Option<Fingerprint> { ) -> Option<Fingerprint> {
(self.hash_result)(hcx, value) (self.hash_result)(hcx, value)
@ -74,10 +75,8 @@ pub trait QueryAccessors<CTX: QueryContext>: QueryConfig {
// Don't use this method to compute query results, instead use the methods on TyCtxt // Don't use this method to compute query results, instead use the methods on TyCtxt
fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value; fn compute_fn(tcx: CTX, key: &Self::Key) -> fn(CTX::DepContext, Self::Key) -> Self::Value;
fn hash_result( fn hash_result(hcx: &mut StableHashingContext<'_>, result: &Self::Value)
hcx: &mut CTX::StableHashingContext, -> Option<Fingerprint>;
result: &Self::Value,
) -> Option<Fingerprint>;
fn handle_cycle_error(tcx: CTX, diag: DiagnosticBuilder<'_>) -> Self::Value; fn handle_cycle_error(tcx: CTX, diag: DiagnosticBuilder<'_>) -> Self::Value;
} }