Retire DepGraphSafe and HashStableContext.
This commit is contained in:
parent
228ca8ef0a
commit
b6033fca02
9 changed files with 29 additions and 151 deletions
|
|
@ -8,7 +8,6 @@ use rustc_errors::Diagnostic;
|
|||
use rustc_hir::def_id::DefId;
|
||||
|
||||
mod dep_node;
|
||||
mod safe;
|
||||
|
||||
pub(crate) use rustc_query_system::dep_graph::DepNodeParams;
|
||||
pub use rustc_query_system::dep_graph::{
|
||||
|
|
@ -17,8 +16,6 @@ pub use rustc_query_system::dep_graph::{
|
|||
};
|
||||
|
||||
pub use dep_node::{label_strs, DepConstructor, DepKind, DepNode, DepNodeExt};
|
||||
pub use safe::AssertDepGraphSafe;
|
||||
pub use safe::DepGraphSafe;
|
||||
|
||||
pub type DepGraph = rustc_query_system::dep_graph::DepGraph<DepKind>;
|
||||
pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps<DepKind>;
|
||||
|
|
@ -189,17 +186,3 @@ impl rustc_query_system::HashStableContext for StableHashingContext<'_> {
|
|||
self.sess().opts.debugging_opts.dep_tasks
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_query_system::HashStableContextProvider<StableHashingContext<'tcx>> for TyCtxt<'tcx> {
|
||||
fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> {
|
||||
self.create_stable_hashing_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl rustc_query_system::HashStableContextProvider<StableHashingContext<'a>>
|
||||
for StableHashingContext<'a>
|
||||
{
|
||||
fn get_stable_hashing_context(&self) -> Self {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +0,0 @@
|
|||
//! The `DepGraphSafe` trait
|
||||
|
||||
use crate::ty::TyCtxt;
|
||||
|
||||
pub use rustc_query_system::dep_graph::{AssertDepGraphSafe, DepGraphSafe};
|
||||
|
||||
/// The type context itself can be used to access all kinds of tracked
|
||||
/// state, but those accesses should always generate read events.
|
||||
impl<'tcx> DepGraphSafe for TyCtxt<'tcx> {}
|
||||
|
|
@ -194,8 +194,6 @@ impl<'a> StableHashingContextProvider<'a> for StableHashingContext<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {}
|
||||
|
||||
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
|
||||
fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) {
|
||||
panic!("Node IDs should not appear in incremental state");
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ use crate::type_::Type;
|
|||
use crate::value::Value;
|
||||
|
||||
use rustc::bug;
|
||||
use rustc::dep_graph::DepGraphSafe;
|
||||
use rustc::mir::mono::CodegenUnit;
|
||||
use rustc::ty::layout::{
|
||||
HasParamEnv, LayoutError, LayoutOf, PointeeInfo, Size, TyLayout, VariantIdx,
|
||||
|
|
@ -90,8 +89,6 @@ pub struct CodegenCx<'ll, 'tcx> {
|
|||
local_gen_sym_counter: Cell<usize>,
|
||||
}
|
||||
|
||||
impl<'ll, 'tcx> DepGraphSafe for CodegenCx<'ll, 'tcx> {}
|
||||
|
||||
pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
|
||||
let reloc_model_arg = match sess.opts.cg.relocation_model {
|
||||
Some(ref s) => &s[..],
|
||||
|
|
|
|||
|
|
@ -20,10 +20,9 @@ use std::sync::atomic::Ordering::Relaxed;
|
|||
use super::debug::EdgeFilter;
|
||||
use super::prev::PreviousDepGraph;
|
||||
use super::query::DepGraphQuery;
|
||||
use super::safe::DepGraphSafe;
|
||||
use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
|
||||
use super::{DepContext, DepKind, DepNode, WorkProductId};
|
||||
use crate::{HashStableContext, HashStableContextProvider};
|
||||
use crate::HashStableContext;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DepGraph<K: DepKind> {
|
||||
|
|
@ -191,18 +190,14 @@ impl<K: DepKind> DepGraph<K> {
|
|||
/// `arg` parameter.
|
||||
///
|
||||
/// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html
|
||||
pub fn with_task<H, C, A, R>(
|
||||
pub fn with_task<Ctxt: DepContext<DepKind = K>, A, R>(
|
||||
&self,
|
||||
key: DepNode<K>,
|
||||
cx: C,
|
||||
cx: Ctxt,
|
||||
arg: A,
|
||||
task: fn(C, A) -> R,
|
||||
hash_result: impl FnOnce(&mut H, &R) -> Option<Fingerprint>,
|
||||
) -> (R, DepNodeIndex)
|
||||
where
|
||||
C: DepGraphSafe + HashStableContextProvider<H>,
|
||||
H: HashStableContext,
|
||||
{
|
||||
task: fn(Ctxt, A) -> R,
|
||||
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
|
||||
) -> (R, DepNodeIndex) {
|
||||
self.with_task_impl(
|
||||
key,
|
||||
cx,
|
||||
|
|
@ -223,13 +218,13 @@ impl<K: DepKind> DepGraph<K> {
|
|||
)
|
||||
}
|
||||
|
||||
fn with_task_impl<H, C, A, R>(
|
||||
fn with_task_impl<Ctxt: DepContext<DepKind = K>, A, R>(
|
||||
&self,
|
||||
key: DepNode<K>,
|
||||
cx: C,
|
||||
cx: Ctxt,
|
||||
arg: A,
|
||||
no_tcx: bool,
|
||||
task: fn(C, A) -> R,
|
||||
task: fn(Ctxt, A) -> R,
|
||||
create_task: fn(DepNode<K>) -> Option<TaskDeps<K>>,
|
||||
finish_task_and_alloc_depnode: fn(
|
||||
&CurrentDepGraph<K>,
|
||||
|
|
@ -237,12 +232,8 @@ impl<K: DepKind> DepGraph<K> {
|
|||
Fingerprint,
|
||||
Option<TaskDeps<K>>,
|
||||
) -> DepNodeIndex,
|
||||
hash_result: impl FnOnce(&mut H, &R) -> Option<Fingerprint>,
|
||||
) -> (R, DepNodeIndex)
|
||||
where
|
||||
C: DepGraphSafe + HashStableContextProvider<H>,
|
||||
H: HashStableContext,
|
||||
{
|
||||
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
|
||||
) -> (R, DepNodeIndex) {
|
||||
if let Some(ref data) = self.data {
|
||||
let task_deps = create_task(key).map(Lock::new);
|
||||
|
||||
|
|
@ -251,7 +242,7 @@ impl<K: DepKind> DepGraph<K> {
|
|||
// anyway so that
|
||||
// - we make sure that the infrastructure works and
|
||||
// - we can get an idea of the runtime cost.
|
||||
let mut hcx = cx.get_stable_hashing_context();
|
||||
let mut hcx = cx.create_stable_hashing_context();
|
||||
|
||||
let result = if no_tcx {
|
||||
task(cx, arg)
|
||||
|
|
@ -335,18 +326,14 @@ impl<K: DepKind> DepGraph<K> {
|
|||
|
||||
/// Executes something within an "eval-always" task which is a task
|
||||
/// that runs whenever anything changes.
|
||||
pub fn with_eval_always_task<H, C, A, R>(
|
||||
pub fn with_eval_always_task<Ctxt: DepContext<DepKind = K>, A, R>(
|
||||
&self,
|
||||
key: DepNode<K>,
|
||||
cx: C,
|
||||
cx: Ctxt,
|
||||
arg: A,
|
||||
task: fn(C, A) -> R,
|
||||
hash_result: impl FnOnce(&mut H, &R) -> Option<Fingerprint>,
|
||||
) -> (R, DepNodeIndex)
|
||||
where
|
||||
C: DepGraphSafe + HashStableContextProvider<H>,
|
||||
H: HashStableContext,
|
||||
{
|
||||
task: fn(Ctxt, A) -> R,
|
||||
hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option<Fingerprint>,
|
||||
) -> (R, DepNodeIndex) {
|
||||
self.with_task_impl(
|
||||
key,
|
||||
cx,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ mod dep_node;
|
|||
mod graph;
|
||||
mod prev;
|
||||
mod query;
|
||||
mod safe;
|
||||
mod serialized;
|
||||
|
||||
pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
|
||||
|
|
@ -11,8 +10,6 @@ pub use graph::WorkProductFileKind;
|
|||
pub use graph::{hash_result, DepGraph, DepNodeColor, DepNodeIndex, TaskDeps, WorkProduct};
|
||||
pub use prev::PreviousDepGraph;
|
||||
pub use query::DepGraphQuery;
|
||||
pub use safe::AssertDepGraphSafe;
|
||||
pub use safe::DepGraphSafe;
|
||||
pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
|
||||
|
||||
use rustc_data_structures::profiling::SelfProfilerRef;
|
||||
|
|
@ -23,7 +20,7 @@ use rustc_errors::Diagnostic;
|
|||
use std::fmt;
|
||||
use std::hash::Hash;
|
||||
|
||||
pub trait DepContext: Copy + DepGraphSafe {
|
||||
pub trait DepContext: Copy {
|
||||
type DepKind: self::DepKind;
|
||||
type StableHashingContext: crate::HashStableContext;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,51 +0,0 @@
|
|||
//! The `DepGraphSafe` trait
|
||||
|
||||
use rustc_ast::ast::NodeId;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::BodyId;
|
||||
|
||||
/// The `DepGraphSafe` trait is used to specify what kinds of values
|
||||
/// are safe to "leak" into a task. The idea is that this should be
|
||||
/// only be implemented for things like the tcx as well as various id
|
||||
/// types, which will create reads in the dep-graph whenever the trait
|
||||
/// loads anything that might depend on the input program.
|
||||
pub trait DepGraphSafe {}
|
||||
|
||||
/// A `BodyId` on its own doesn't give access to any particular state.
|
||||
/// You must fetch the state from the various maps or generate
|
||||
/// on-demand queries, all of which create reads.
|
||||
impl DepGraphSafe for BodyId {}
|
||||
|
||||
/// A `NodeId` on its own doesn't give access to any particular state.
|
||||
/// You must fetch the state from the various maps or generate
|
||||
/// on-demand queries, all of which create reads.
|
||||
impl DepGraphSafe for NodeId {}
|
||||
|
||||
/// A `DefId` on its own doesn't give access to any particular state.
|
||||
/// You must fetch the state from the various maps or generate
|
||||
/// on-demand queries, all of which create reads.
|
||||
impl DepGraphSafe for DefId {}
|
||||
|
||||
/// Tuples make it easy to build up state.
|
||||
impl<A, B> DepGraphSafe for (A, B)
|
||||
where
|
||||
A: DepGraphSafe,
|
||||
B: DepGraphSafe,
|
||||
{
|
||||
}
|
||||
|
||||
/// Shared ref to dep-graph-safe stuff should still be dep-graph-safe.
|
||||
impl<'a, A> DepGraphSafe for &'a A where A: DepGraphSafe {}
|
||||
|
||||
/// Mut ref to dep-graph-safe stuff should still be dep-graph-safe.
|
||||
impl<'a, A> DepGraphSafe for &'a mut A where A: DepGraphSafe {}
|
||||
|
||||
/// No data here! :)
|
||||
impl DepGraphSafe for () {}
|
||||
|
||||
/// A convenient override that lets you pass arbitrary state into a
|
||||
/// task. Every use should be accompanied by a comment explaining why
|
||||
/// it makes sense (or how it could be refactored away in the future).
|
||||
pub struct AssertDepGraphSafe<T>(pub T);
|
||||
|
||||
impl<T> DepGraphSafe for AssertDepGraphSafe<T> {}
|
||||
|
|
@ -19,20 +19,3 @@ pub mod query;
|
|||
pub trait HashStableContext {
|
||||
fn debug_dep_tasks(&self) -> bool;
|
||||
}
|
||||
|
||||
/// Something that can provide a stable hashing context.
|
||||
pub trait HashStableContextProvider<Ctxt> {
|
||||
fn get_stable_hashing_context(&self) -> Ctxt;
|
||||
}
|
||||
|
||||
impl<Ctxt, T: HashStableContextProvider<Ctxt>> HashStableContextProvider<Ctxt> for &T {
|
||||
fn get_stable_hashing_context(&self) -> Ctxt {
|
||||
(**self).get_stable_hashing_context()
|
||||
}
|
||||
}
|
||||
|
||||
impl<Ctxt, T: HashStableContextProvider<Ctxt>> HashStableContextProvider<Ctxt> for &mut T {
|
||||
fn get_stable_hashing_context(&self) -> Ctxt {
|
||||
(**self).get_stable_hashing_context()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,12 +2,11 @@
|
|||
//! generate the actual methods on tcx which find and execute the provider,
|
||||
//! manage the caches, and so forth.
|
||||
|
||||
use crate::dep_graph::{DepContext, DepKind, DepNode};
|
||||
use crate::dep_graph::{DepKind, DepNode};
|
||||
use crate::dep_graph::{DepNodeIndex, SerializedDepNodeIndex};
|
||||
use crate::query::caches::QueryCache;
|
||||
use crate::query::config::{QueryContext, QueryDescription};
|
||||
use crate::query::job::{QueryInfo, QueryJob, QueryJobId, QueryJobInfo, QueryShardJobId};
|
||||
use crate::HashStableContextProvider;
|
||||
|
||||
#[cfg(not(parallel_compiler))]
|
||||
use rustc_data_structures::cold_path;
|
||||
|
|
@ -382,7 +381,7 @@ where
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn try_execute_query<Q, CTX, K>(
|
||||
fn try_execute_query<Q, CTX>(
|
||||
tcx: CTX,
|
||||
span: Span,
|
||||
key: Q::Key,
|
||||
|
|
@ -390,9 +389,7 @@ fn try_execute_query<Q, CTX, K>(
|
|||
) -> Q::Value
|
||||
where
|
||||
Q: QueryDescription<CTX>,
|
||||
CTX: QueryContext<DepKind = K>,
|
||||
CTX: HashStableContextProvider<<CTX as DepContext>::StableHashingContext>,
|
||||
K: DepKind,
|
||||
CTX: QueryContext,
|
||||
{
|
||||
let job = match JobOwner::try_start::<Q, _>(tcx, span, &key, lookup) {
|
||||
TryGetJob::NotYetStarted(job) => job,
|
||||
|
|
@ -408,7 +405,7 @@ where
|
|||
// expensive for some `DepKind`s.
|
||||
if !tcx.dep_graph().is_fully_enabled() {
|
||||
let null_dep_node = DepNode::new_no_params(DepKind::NULL);
|
||||
return force_query_with_job::<Q, _, _>(tcx, key, job, null_dep_node).0;
|
||||
return force_query_with_job::<Q, _>(tcx, key, job, null_dep_node).0;
|
||||
}
|
||||
|
||||
if Q::ANON {
|
||||
|
|
@ -460,7 +457,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
let (result, dep_node_index) = force_query_with_job::<Q, _, _>(tcx, key, job, dep_node);
|
||||
let (result, dep_node_index) = force_query_with_job::<Q, _>(tcx, key, job, dep_node);
|
||||
tcx.dep_graph().read_index(dep_node_index);
|
||||
result
|
||||
}
|
||||
|
|
@ -554,7 +551,7 @@ fn incremental_verify_ich<Q, CTX>(
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn force_query_with_job<Q, CTX, K>(
|
||||
fn force_query_with_job<Q, CTX>(
|
||||
tcx: CTX,
|
||||
key: Q::Key,
|
||||
job: JobOwner<'_, CTX, Q::Cache>,
|
||||
|
|
@ -562,9 +559,7 @@ fn force_query_with_job<Q, CTX, K>(
|
|||
) -> (Q::Value, DepNodeIndex)
|
||||
where
|
||||
Q: QueryDescription<CTX>,
|
||||
CTX: QueryContext<DepKind = K>,
|
||||
CTX: HashStableContextProvider<<CTX as DepContext>::StableHashingContext>,
|
||||
K: DepKind,
|
||||
CTX: QueryContext,
|
||||
{
|
||||
// If the following assertion triggers, it can have two reasons:
|
||||
// 1. Something is wrong with DepNode creation, either here or
|
||||
|
|
@ -631,11 +626,9 @@ pub trait QueryGetter: QueryContext {
|
|||
);
|
||||
}
|
||||
|
||||
impl<CTX, K> QueryGetter for CTX
|
||||
impl<CTX> QueryGetter for CTX
|
||||
where
|
||||
CTX: QueryContext<DepKind = K>,
|
||||
CTX: HashStableContextProvider<<CTX as DepContext>::StableHashingContext>,
|
||||
K: DepKind,
|
||||
CTX: QueryContext,
|
||||
{
|
||||
#[inline(never)]
|
||||
fn get_query<Q: QueryDescription<Self>>(self, span: Span, key: Q::Key) -> Q::Value {
|
||||
|
|
@ -649,7 +642,7 @@ where
|
|||
self.dep_graph().read_index(index);
|
||||
value.clone()
|
||||
},
|
||||
|key, lookup| try_execute_query::<Q, _, _>(self, span, key, lookup),
|
||||
|key, lookup| try_execute_query::<Q, _>(self, span, key, lookup),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -710,7 +703,7 @@ where
|
|||
#[cfg(parallel_compiler)]
|
||||
TryGetJob::JobCompleted(_) => return,
|
||||
};
|
||||
force_query_with_job::<Q, _, _>(self, key, job, dep_node);
|
||||
force_query_with_job::<Q, _>(self, key, job, dep_node);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue