From: Camille GILLOT Date: Tue, 24 Mar 2020 19:09:06 +0000 (+0100) Subject: Retire DepGraphSafe and HashStableContext. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=b6033fca02d87955ac7f391cdcbeb4707d2c8f02;p=rust.git Retire DepGraphSafe and HashStableContext. --- diff --git a/src/librustc/dep_graph/mod.rs b/src/librustc/dep_graph/mod.rs index 4d9d439c526..de94b6b1850 100644 --- a/src/librustc/dep_graph/mod.rs +++ b/src/librustc/dep_graph/mod.rs @@ -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; pub type TaskDeps = rustc_query_system::dep_graph::TaskDeps; @@ -189,17 +186,3 @@ fn debug_dep_tasks(&self) -> bool { self.sess().opts.debugging_opts.dep_tasks } } - -impl rustc_query_system::HashStableContextProvider> for TyCtxt<'tcx> { - fn get_stable_hashing_context(&self) -> StableHashingContext<'tcx> { - self.create_stable_hashing_context() - } -} - -impl rustc_query_system::HashStableContextProvider> - 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 index 47a1c09672f..00000000000 --- a/src/librustc/dep_graph/safe.rs +++ /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> {} diff --git a/src/librustc/ich/hcx.rs b/src/librustc/ich/hcx.rs index a9466e8252d..ac3faae072b 100644 --- a/src/librustc/ich/hcx.rs +++ b/src/librustc/ich/hcx.rs @@ -194,8 +194,6 @@ fn get_stable_hashing_context(&self) -> StableHashingContext<'a> { } } -impl<'a> crate::dep_graph::DepGraphSafe for StableHashingContext<'a> {} - impl<'a> HashStable> for ast::NodeId { fn hash_stable(&self, _: &mut StableHashingContext<'a>, _: &mut StableHasher) { panic!("Node IDs should not appear in incremental state"); diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 92f59feef90..7e87f45ba4b 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -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, } -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[..], diff --git a/src/librustc_query_system/dep_graph/graph.rs b/src/librustc_query_system/dep_graph/graph.rs index 7352551559c..60c5dcda425 100644 --- a/src/librustc_query_system/dep_graph/graph.rs +++ b/src/librustc_query_system/dep_graph/graph.rs @@ -20,10 +20,9 @@ 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 { @@ -191,18 +190,14 @@ pub fn with_ignore(&self, op: OP) -> R /// `arg` parameter. /// /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/incremental-compilation.html - pub fn with_task( + pub fn with_task, A, R>( &self, key: DepNode, - cx: C, + cx: Ctxt, arg: A, - task: fn(C, A) -> R, - hash_result: impl FnOnce(&mut H, &R) -> Option, - ) -> (R, DepNodeIndex) - where - C: DepGraphSafe + HashStableContextProvider, - H: HashStableContext, - { + task: fn(Ctxt, A) -> R, + hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option, + ) -> (R, DepNodeIndex) { self.with_task_impl( key, cx, @@ -223,13 +218,13 @@ pub fn with_task( ) } - fn with_task_impl( + fn with_task_impl, A, R>( &self, key: DepNode, - cx: C, + cx: Ctxt, arg: A, no_tcx: bool, - task: fn(C, A) -> R, + task: fn(Ctxt, A) -> R, create_task: fn(DepNode) -> Option>, finish_task_and_alloc_depnode: fn( &CurrentDepGraph, @@ -237,12 +232,8 @@ fn with_task_impl( Fingerprint, Option>, ) -> DepNodeIndex, - hash_result: impl FnOnce(&mut H, &R) -> Option, - ) -> (R, DepNodeIndex) - where - C: DepGraphSafe + HashStableContextProvider, - H: HashStableContext, - { + hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option, + ) -> (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( // 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(&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( + pub fn with_eval_always_task, A, R>( &self, key: DepNode, - cx: C, + cx: Ctxt, arg: A, - task: fn(C, A) -> R, - hash_result: impl FnOnce(&mut H, &R) -> Option, - ) -> (R, DepNodeIndex) - where - C: DepGraphSafe + HashStableContextProvider, - H: HashStableContext, - { + task: fn(Ctxt, A) -> R, + hash_result: impl FnOnce(&mut Ctxt::StableHashingContext, &R) -> Option, + ) -> (R, DepNodeIndex) { self.with_task_impl( key, cx, diff --git a/src/librustc_query_system/dep_graph/mod.rs b/src/librustc_query_system/dep_graph/mod.rs index 2faca546213..f215dadc660 100644 --- a/src/librustc_query_system/dep_graph/mod.rs +++ b/src/librustc_query_system/dep_graph/mod.rs @@ -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 index 7bba348f884..00000000000 --- a/src/librustc_query_system/dep_graph/safe.rs +++ /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 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(pub T); - -impl DepGraphSafe for AssertDepGraphSafe {} diff --git a/src/librustc_query_system/lib.rs b/src/librustc_query_system/lib.rs index 5750d8e8c35..1f7fde642eb 100644 --- a/src/librustc_query_system/lib.rs +++ b/src/librustc_query_system/lib.rs @@ -19,20 +19,3 @@ pub trait HashStableContext { fn debug_dep_tasks(&self) -> bool; } - -/// Something that can provide a stable hashing context. -pub trait HashStableContextProvider { - fn get_stable_hashing_context(&self) -> Ctxt; -} - -impl> HashStableContextProvider for &T { - fn get_stable_hashing_context(&self) -> Ctxt { - (**self).get_stable_hashing_context() - } -} - -impl> HashStableContextProvider for &mut T { - fn get_stable_hashing_context(&self) -> Ctxt { - (**self).get_stable_hashing_context() - } -} diff --git a/src/librustc_query_system/query/plumbing.rs b/src/librustc_query_system/query/plumbing.rs index cf23467cf99..f025a056512 100644 --- a/src/librustc_query_system/query/plumbing.rs +++ b/src/librustc_query_system/query/plumbing.rs @@ -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( } #[inline(always)] -fn try_execute_query( +fn try_execute_query( tcx: CTX, span: Span, key: Q::Key, @@ -390,9 +389,7 @@ fn try_execute_query( ) -> Q::Value where Q: QueryDescription, - CTX: QueryContext, - CTX: HashStableContextProvider<::StableHashingContext>, - K: DepKind, + CTX: QueryContext, { let job = match JobOwner::try_start::(tcx, span, &key, lookup) { TryGetJob::NotYetStarted(job) => job, @@ -408,7 +405,7 @@ fn try_execute_query( // 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::(tcx, key, job, null_dep_node).0; + return force_query_with_job::(tcx, key, job, null_dep_node).0; } if Q::ANON { @@ -460,7 +457,7 @@ fn try_execute_query( } } - let (result, dep_node_index) = force_query_with_job::(tcx, key, job, dep_node); + let (result, dep_node_index) = force_query_with_job::(tcx, key, job, dep_node); tcx.dep_graph().read_index(dep_node_index); result } @@ -554,7 +551,7 @@ fn incremental_verify_ich( } #[inline(always)] -fn force_query_with_job( +fn force_query_with_job( tcx: CTX, key: Q::Key, job: JobOwner<'_, CTX, Q::Cache>, @@ -562,9 +559,7 @@ fn force_query_with_job( ) -> (Q::Value, DepNodeIndex) where Q: QueryDescription, - CTX: QueryContext, - CTX: HashStableContextProvider<::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>( ); } -impl QueryGetter for CTX +impl QueryGetter for CTX where - CTX: QueryContext, - CTX: HashStableContextProvider<::StableHashingContext>, - K: DepKind, + CTX: QueryContext, { #[inline(never)] fn get_query>(self, span: Span, key: Q::Key) -> Q::Value { @@ -649,7 +642,7 @@ fn get_query>(self, span: Span, key: Q::Key) -> Q::Val self.dep_graph().read_index(index); value.clone() }, - |key, lookup| try_execute_query::(self, span, key, lookup), + |key, lookup| try_execute_query::(self, span, key, lookup), ) } @@ -710,7 +703,7 @@ fn force_query>( #[cfg(parallel_compiler)] TryGetJob::JobCompleted(_) => return, }; - force_query_with_job::(self, key, job, dep_node); + force_query_with_job::(self, key, job, dep_node); }, ); }