Access the session directly from DepContext.

This commit is contained in:
Camille GILLOT 2020-11-12 20:48:37 +01:00
parent 83b30a639d
commit f96e960ccf
9 changed files with 21 additions and 40 deletions

View File

@ -4203,6 +4203,7 @@ dependencies = [
"rustc_index", "rustc_index",
"rustc_macros", "rustc_macros",
"rustc_serialize", "rustc_serialize",
"rustc_session",
"rustc_span", "rustc_span",
"smallvec 1.6.1", "smallvec 1.6.1",
"tracing", "tracing",

View File

@ -2,6 +2,7 @@ use crate::ich::StableHashingContext;
use crate::ty::{self, TyCtxt}; use crate::ty::{self, TyCtxt};
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_session::Session;
#[macro_use] #[macro_use]
mod dep_node; mod dep_node;
@ -101,20 +102,18 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
TyCtxt::create_stable_hashing_context(*self) 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] #[inline]
fn dep_graph(&self) -> &DepGraph { fn dep_graph(&self) -> &DepGraph {
&self.dep_graph &self.dep_graph
} }
#[inline(always)]
fn profiler(&self) -> &SelfProfilerRef { fn profiler(&self) -> &SelfProfilerRef {
&self.prof &self.prof
} }
#[inline(always)]
fn sess(&self) -> &Session {
self.sess
}
} }

View File

@ -47,13 +47,6 @@ impl HasDepContext for QueryCtxt<'tcx> {
impl QueryContext for QueryCtxt<'tcx> { impl QueryContext for QueryCtxt<'tcx> {
type Query = Query<'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 { fn def_path_str(&self, def_id: DefId) -> String {
self.tcx.def_path_str(def_id) self.tcx.def_path_str(def_id)
} }
@ -132,14 +125,6 @@ impl QueryContext for QueryCtxt<'tcx> {
(cb.force_from_dep_node)(*self, dep_node) (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 // Interactions with on_disk_cache
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> { fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic> {
self.on_disk_cache self.on_disk_cache

View File

@ -16,6 +16,7 @@ rustc_errors = { path = "../rustc_errors" }
rustc_macros = { path = "../rustc_macros" } rustc_macros = { path = "../rustc_macros" }
rustc_index = { path = "../rustc_index" } rustc_index = { path = "../rustc_index" }
rustc_serialize = { path = "../rustc_serialize" } rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
parking_lot = "0.11" parking_lot = "0.11"
smallvec = { version = "1.6.1", features = ["union", "may_dangle"] } smallvec = { version = "1.6.1", features = ["union", "may_dangle"] }

View File

@ -87,7 +87,10 @@ impl<K: DepKind> DepNode<K> {
#[cfg(debug_assertions)] #[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)); tcx.dep_graph().register_dep_node_debug_str(dep_node, || arg.to_debug_str(tcx));
} }
} }

View File

@ -280,7 +280,7 @@ impl<K: DepKind> DepGraph<K> {
let mut hcx = dcx.create_stable_hashing_context(); let mut hcx = dcx.create_stable_hashing_context();
let current_fingerprint = hash_result(&mut hcx, &result); 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`. // Intern the new `DepNode`.
let dep_node_index = if let Some(prev_index) = data.previous.node_to_index_opt(&key) { let dep_node_index = if let Some(prev_index) = data.previous.node_to_index_opt(&key) {
@ -731,7 +731,7 @@ impl<K: DepKind> DepGraph<K> {
return None; return None;
} }
None => { None => {
if !tcx.has_errors_or_delayed_span_bugs() { if !tcx.dep_context().sess().has_errors_or_delayed_span_bugs() {
panic!( panic!(
"try_mark_previous_green() - Forcing the DepNode \ "try_mark_previous_green() - Forcing the DepNode \
should have set its color" should have set its color"
@ -835,7 +835,7 @@ impl<K: DepKind> DepGraph<K> {
// Promote the previous diagnostics to the current session. // Promote the previous diagnostics to the current session.
tcx.store_diagnostics(dep_node_index, diagnostics.clone().into()); tcx.store_diagnostics(dep_node_index, diagnostics.clone().into());
let handle = tcx.diagnostic(); let handle = tcx.dep_context().sess().diagnostic();
for diagnostic in diagnostics { for diagnostic in diagnostics {
handle.emit_diagnostic(&diagnostic); handle.emit_diagnostic(&diagnostic);

View File

@ -13,6 +13,7 @@ pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
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_session::Session;
use std::fmt; use std::fmt;
use std::hash::Hash; use std::hash::Hash;
@ -24,9 +25,6 @@ pub trait DepContext: Copy {
/// 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) -> Self::StableHashingContext;
fn debug_dep_tasks(&self) -> bool;
fn debug_dep_node(&self) -> bool;
/// Access the DepGraph. /// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>; fn dep_graph(&self) -> &DepGraph<Self::DepKind>;
@ -34,6 +32,9 @@ pub trait DepContext: Copy {
/// Access the profiler. /// Access the profiler.
fn profiler(&self) -> &SelfProfilerRef; fn profiler(&self) -> &SelfProfilerRef;
/// Access the compiler session.
fn sess(&self) -> &Session;
} }
pub trait HasDepContext: Copy { pub trait HasDepContext: Copy {

View File

@ -26,9 +26,6 @@ use rustc_span::def_id::DefId;
pub trait QueryContext: HasDepContext { pub trait QueryContext: HasDepContext {
type Query: Clone + HashStable<Self::StableHashingContext>; type Query: Clone + HashStable<Self::StableHashingContext>;
fn incremental_verify_ich(&self) -> bool;
fn verbose(&self) -> bool;
/// Get string representation from DefPath. /// Get string representation from DefPath.
fn def_path_str(&self, def_id: DefId) -> String; 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. /// Try to force a dep node to execute and see if it's green.
fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> bool; fn try_force_from_dep_node(&self, dep_node: &DepNode<Self::DepKind>) -> 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. /// Load diagnostics associated to the node in the previous session.
fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>; fn load_diagnostics(&self, prev_dep_node_index: SerializedDepNodeIndex) -> Vec<Diagnostic>;

View File

@ -550,7 +550,7 @@ where
// If `-Zincremental-verify-ich` is specified, re-hash results from // If `-Zincremental-verify-ich` is specified, re-hash results from
// the cache and make sure that they have the expected fingerprint. // 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); incremental_verify_ich(*tcx.dep_context(), &result, dep_node, dep_node_index, query);
} }