From f96e960ccfa92895217562ede43043405194eab0 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 12 Nov 2020 20:48:37 +0100 Subject: [PATCH] Access the session directly from DepContext. --- Cargo.lock | 1 + compiler/rustc_middle/src/dep_graph/mod.rs | 15 +++++++-------- compiler/rustc_query_impl/src/plumbing.rs | 15 --------------- compiler/rustc_query_system/Cargo.toml | 1 + .../rustc_query_system/src/dep_graph/dep_node.rs | 5 ++++- .../rustc_query_system/src/dep_graph/graph.rs | 6 +++--- compiler/rustc_query_system/src/dep_graph/mod.rs | 7 ++++--- compiler/rustc_query_system/src/query/mod.rs | 9 --------- compiler/rustc_query_system/src/query/plumbing.rs | 2 +- 9 files changed, 21 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0576a55a4472..4f16bf6ca3ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4203,6 +4203,7 @@ dependencies = [ "rustc_index", "rustc_macros", "rustc_serialize", + "rustc_session", "rustc_span", "smallvec 1.6.1", "tracing", diff --git a/compiler/rustc_middle/src/dep_graph/mod.rs b/compiler/rustc_middle/src/dep_graph/mod.rs index d862db2674eb..c688b23be1d0 100644 --- a/compiler/rustc_middle/src/dep_graph/mod.rs +++ b/compiler/rustc_middle/src/dep_graph/mod.rs @@ -2,6 +2,7 @@ use crate::ich::StableHashingContext; use crate::ty::{self, TyCtxt}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sync::Lock; +use rustc_session::Session; #[macro_use] mod dep_node; @@ -101,20 +102,18 @@ impl<'tcx> DepContext for TyCtxt<'tcx> { TyCtxt::create_stable_hashing_context(*self) } - fn debug_dep_tasks(&self) -> bool { - self.sess.opts.debugging_opts.dep_tasks - } - fn debug_dep_node(&self) -> bool { - self.sess.opts.debugging_opts.incremental_info - || self.sess.opts.debugging_opts.query_dep_graph - } - #[inline] fn dep_graph(&self) -> &DepGraph { &self.dep_graph } + #[inline(always)] fn profiler(&self) -> &SelfProfilerRef { &self.prof } + + #[inline(always)] + fn sess(&self) -> &Session { + self.sess + } } diff --git a/compiler/rustc_query_impl/src/plumbing.rs b/compiler/rustc_query_impl/src/plumbing.rs index d4093f281ddd..100e9c5ceb03 100644 --- a/compiler/rustc_query_impl/src/plumbing.rs +++ b/compiler/rustc_query_impl/src/plumbing.rs @@ -47,13 +47,6 @@ impl HasDepContext for QueryCtxt<'tcx> { impl QueryContext for QueryCtxt<'tcx> { type Query = Query<'tcx>; - fn incremental_verify_ich(&self) -> bool { - self.sess.opts.debugging_opts.incremental_verify_ich - } - fn verbose(&self) -> bool { - self.sess.verbose() - } - fn def_path_str(&self, def_id: DefId) -> String { self.tcx.def_path_str(def_id) } @@ -132,14 +125,6 @@ impl QueryContext for QueryCtxt<'tcx> { (cb.force_from_dep_node)(*self, dep_node) } - fn has_errors_or_delayed_span_bugs(&self) -> bool { - self.sess.has_errors_or_delayed_span_bugs() - } - - fn diagnostic(&self) -> &rustc_errors::Handler { - self.sess.diagnostic() - } - // Interactions with on_disk_cache fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec { self.on_disk_cache diff --git a/compiler/rustc_query_system/Cargo.toml b/compiler/rustc_query_system/Cargo.toml index d18a2a6faed6..7d3357f8fa2e 100644 --- a/compiler/rustc_query_system/Cargo.toml +++ b/compiler/rustc_query_system/Cargo.toml @@ -16,6 +16,7 @@ rustc_errors = { path = "../rustc_errors" } rustc_macros = { path = "../rustc_macros" } rustc_index = { path = "../rustc_index" } rustc_serialize = { path = "../rustc_serialize" } +rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } parking_lot = "0.11" smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_query_system/src/dep_graph/dep_node.rs b/compiler/rustc_query_system/src/dep_graph/dep_node.rs index 1319a31b8f54..f55e2f777a26 100644 --- a/compiler/rustc_query_system/src/dep_graph/dep_node.rs +++ b/compiler/rustc_query_system/src/dep_graph/dep_node.rs @@ -87,7 +87,10 @@ impl DepNode { #[cfg(debug_assertions)] { - if !kind.can_reconstruct_query_key() && tcx.debug_dep_node() { + if !kind.can_reconstruct_query_key() + && (tcx.sess().opts.debugging_opts.incremental_info + || tcx.sess().opts.debugging_opts.query_dep_graph) + { tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx)); } } diff --git a/compiler/rustc_query_system/src/dep_graph/graph.rs b/compiler/rustc_query_system/src/dep_graph/graph.rs index f579052c106b..0f25572170f5 100644 --- a/compiler/rustc_query_system/src/dep_graph/graph.rs +++ b/compiler/rustc_query_system/src/dep_graph/graph.rs @@ -280,7 +280,7 @@ impl DepGraph { let mut hcx = dcx.create_stable_hashing_context(); let current_fingerprint = hash_result(&mut hcx, &result); - let print_status = cfg!(debug_assertions) && dcx.debug_dep_tasks(); + let print_status = cfg!(debug_assertions) && dcx.sess().opts.debugging_opts.dep_tasks; // Intern the new `DepNode`. let dep_node_index = if let Some(prev_index) = data.previous.node_to_index_opt(&key) { @@ -731,7 +731,7 @@ impl DepGraph { return None; } None => { - if !tcx.has_errors_or_delayed_span_bugs() { + if !tcx.dep_context().sess().has_errors_or_delayed_span_bugs() { panic!( "try_mark_previous_green() - Forcing the DepNode \ should have set its color" @@ -835,7 +835,7 @@ impl DepGraph { // Promote the previous diagnostics to the current session. tcx.store_diagnostics(dep_node_index, diagnostics.clone().into()); - let handle = tcx.diagnostic(); + let handle = tcx.dep_context().sess().diagnostic(); for diagnostic in diagnostics { handle.emit_diagnostic(&diagnostic); diff --git a/compiler/rustc_query_system/src/dep_graph/mod.rs b/compiler/rustc_query_system/src/dep_graph/mod.rs index a647381fb03f..e8fb71be3e08 100644 --- a/compiler/rustc_query_system/src/dep_graph/mod.rs +++ b/compiler/rustc_query_system/src/dep_graph/mod.rs @@ -13,6 +13,7 @@ pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex}; use rustc_data_structures::profiling::SelfProfilerRef; use rustc_data_structures::sync::Lock; +use rustc_session::Session; use std::fmt; use std::hash::Hash; @@ -24,9 +25,6 @@ pub trait DepContext: Copy { /// Create a hashing context for hashing new results. fn create_stable_hashing_context(&self) -> Self::StableHashingContext; - fn debug_dep_tasks(&self) -> bool; - fn debug_dep_node(&self) -> bool; - /// Access the DepGraph. fn dep_graph(&self) -> &DepGraph; @@ -34,6 +32,9 @@ pub trait DepContext: Copy { /// Access the profiler. fn profiler(&self) -> &SelfProfilerRef; + + /// Access the compiler session. + fn sess(&self) -> &Session; } pub trait HasDepContext: Copy { diff --git a/compiler/rustc_query_system/src/query/mod.rs b/compiler/rustc_query_system/src/query/mod.rs index c935e1b9c5cd..bc5ad2cc3852 100644 --- a/compiler/rustc_query_system/src/query/mod.rs +++ b/compiler/rustc_query_system/src/query/mod.rs @@ -26,9 +26,6 @@ use rustc_span::def_id::DefId; pub trait QueryContext: HasDepContext { type Query: Clone + HashStable; - fn incremental_verify_ich(&self) -> bool; - fn verbose(&self) -> bool; - /// Get string representation from DefPath. fn def_path_str(&self, def_id: DefId) -> String; @@ -43,12 +40,6 @@ pub trait QueryContext: HasDepContext { /// Try to force a dep node to execute and see if it's green. fn try_force_from_dep_node(&self, dep_node: &DepNode) -> bool; - /// Return whether the current session is tainted by errors. - fn has_errors_or_delayed_span_bugs(&self) -> bool; - - /// Return the diagnostic handler. - fn diagnostic(&self) -> &rustc_errors::Handler; - /// Load diagnostics associated to the node in the previous session. fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec; diff --git a/compiler/rustc_query_system/src/query/plumbing.rs b/compiler/rustc_query_system/src/query/plumbing.rs index bd22ee2c18b2..fdc73dcc5408 100644 --- a/compiler/rustc_query_system/src/query/plumbing.rs +++ b/compiler/rustc_query_system/src/query/plumbing.rs @@ -550,7 +550,7 @@ where // If `-Zincremental-verify-ich` is specified, re-hash results from // the cache and make sure that they have the expected fingerprint. - if unlikely!(tcx.incremental_verify_ich()) { + if unlikely!(tcx.dep_context().sess().opts.debugging_opts.incremental_verify_ich) { incremental_verify_ich(*tcx.dep_context(), &result, dep_node, dep_node_index, query); }