]> git.lizzy.rs Git - rust.git/commitdiff
Retire DepGraphSafe and HashStableContext.
authorCamille GILLOT <gillot.camille@gmail.com>
Tue, 24 Mar 2020 19:09:06 +0000 (20:09 +0100)
committerCamille GILLOT <gillot.camille@gmail.com>
Thu, 26 Mar 2020 08:40:51 +0000 (09:40 +0100)
src/librustc/dep_graph/mod.rs
src/librustc/dep_graph/safe.rs [deleted file]
src/librustc/ich/hcx.rs
src/librustc_codegen_llvm/context.rs
src/librustc_query_system/dep_graph/graph.rs
src/librustc_query_system/dep_graph/mod.rs
src/librustc_query_system/dep_graph/safe.rs [deleted file]
src/librustc_query_system/lib.rs
src/librustc_query_system/query/plumbing.rs

index 4d9d439c526e6606ab58567b6e0eaed1317f50dd..de94b6b1850d7ea63771bdc8553e2334bf1cb656 100644 (file)
@@ -8,7 +8,6 @@
 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 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 @@ fn debug_dep_tasks(&self) -> bool {
         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()
-    }
-}
diff --git a/src/librustc/dep_graph/safe.rs b/src/librustc/dep_graph/safe.rs
deleted file mode 100644 (file)
index 47a1c09..0000000
+++ /dev/null
@@ -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> {}
index a9466e8252de7217db9fc43e62aba4fff6fc8956..ac3faae072b68c6a535c478d8cbf6c9ae2690950 100644 (file)
@@ -194,8 +194,6 @@ fn get_stable_hashing_context(&self) -> 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");
index 92f59feef90fefba9239a5073fed4803e7fac61f..7e87f45ba4bb1b48ab548b0aac4563b51f3f72fc 100644 (file)
@@ -7,7 +7,6 @@
 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[..],
index 7352551559cf4835c4eb32288b51d4e114ac5e8f..60c5dcda42515e8fdfbd91920df5fa4521222ecb 100644 (file)
 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 @@ pub fn with_ignore<OP, R>(&self, op: OP) -> R
     ///   `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 @@ pub fn with_task<H, C, A, R>(
         )
     }
 
-    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 @@ fn with_task_impl<H, C, A, R>(
             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 @@ fn with_task_impl<H, C, A, R>(
             // 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 @@ pub fn with_anon_task<OP, R>(&self, dep_kind: K, op: OP) -> (R, DepNodeIndex)
 
     /// 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,
index 2faca54621340fb1b8d080d352ef313070b57555..f215dadc6608ff08c0a7e155ab7a8a6a41085b56 100644 (file)
@@ -3,7 +3,6 @@
 mod graph;
 mod prev;
 mod query;
-mod safe;
 mod serialized;
 
 pub use dep_node::{DepNode, DepNodeParams, WorkProductId};
@@ -11,8 +10,6 @@
 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 std::fmt;
 use std::hash::Hash;
 
-pub trait DepContext: Copy + DepGraphSafe {
+pub trait DepContext: Copy {
     type DepKind: self::DepKind;
     type StableHashingContext: crate::HashStableContext;
 
diff --git a/src/librustc_query_system/dep_graph/safe.rs b/src/librustc_query_system/dep_graph/safe.rs
deleted file mode 100644 (file)
index 7bba348..0000000
+++ /dev/null
@@ -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> {}
index 5750d8e8c3518d863e7b8d9fdd28831ffaf6cac5..1f7fde642eb41306db340b5c7287c5676ece2134 100644 (file)
 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()
-    }
-}
index cf23467cf99fc125c5a365843ac775b02547bfc6..f025a056512b98a40e4ceea9e36d922564949717 100644 (file)
@@ -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 @@ fn try_get_cached<CTX, C, R, OnHit, OnMiss>(
 }
 
 #[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 @@ fn try_execute_query<Q, CTX, K>(
     // 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 @@ fn try_execute_query<Q, CTX, K>(
         }
     }
 
-    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 @@ fn force_query<Q: QueryDescription<Self>>(
     );
 }
 
-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 @@ fn get_query<Q: QueryDescription<Self>>(self, span: Span, key: Q::Key) -> Q::Val
                 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 @@ fn force_query<Q: QueryDescription<Self>>(
                     #[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);
             },
         );
     }