1
Fork 0

Pass tcx directly

This commit is contained in:
John Kåre Alsaker 2023-03-25 03:13:05 +01:00
parent afe4c16b29
commit 820e3a8d6a
3 changed files with 26 additions and 37 deletions

View file

@ -71,7 +71,6 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
} }
impl<'tcx> DepContext for TyCtxt<'tcx> { impl<'tcx> DepContext for TyCtxt<'tcx> {
type Implicit<'a> = TyCtxt<'a>;
type DepKind = DepKind; type DepKind = DepKind;
#[inline] #[inline]
@ -79,11 +78,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
TyCtxt::with_stable_hashing_context(self, f) TyCtxt::with_stable_hashing_context(self, f)
} }
#[inline]
fn with_context<R>(f: impl FnOnce(TyCtxt<'_>) -> R) -> R {
ty::tls::with(|tcx| f(tcx))
}
#[inline] #[inline]
fn dep_graph(&self) -> &DepGraph { fn dep_graph(&self) -> &DepGraph {
&self.dep_graph &self.dep_graph

View file

@ -23,15 +23,11 @@ use std::{fmt, panic};
use self::graph::{print_markframe_trace, MarkFrame}; use self::graph::{print_markframe_trace, MarkFrame};
pub trait DepContext: Copy { pub trait DepContext: Copy {
type Implicit<'a>: DepContext;
type DepKind: self::DepKind; type DepKind: self::DepKind;
/// Create a hashing context for hashing new results. /// Create a hashing context for hashing new results.
fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R; fn with_stable_hashing_context<R>(self, f: impl FnOnce(StableHashingContext<'_>) -> R) -> R;
/// Access the implicit context.
fn with_context<R>(f: impl FnOnce(Self::Implicit<'_>) -> R) -> R;
/// Access the DepGraph. /// Access the DepGraph.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>; fn dep_graph(&self) -> &DepGraph<Self::DepKind>;

View file

@ -641,7 +641,7 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
Tcx: DepContext, Tcx: DepContext,
{ {
if !dep_graph_data.is_index_green(prev_index) { if !dep_graph_data.is_index_green(prev_index) {
incremental_verify_ich_not_green::<Tcx>(prev_index) incremental_verify_ich_not_green(tcx, prev_index)
} }
let new_hash = hash_result.map_or(Fingerprint::ZERO, |f| { let new_hash = hash_result.map_or(Fingerprint::ZERO, |f| {
@ -651,22 +651,20 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
let old_hash = dep_graph_data.prev_fingerprint_of(prev_index); let old_hash = dep_graph_data.prev_fingerprint_of(prev_index);
if new_hash != old_hash { if new_hash != old_hash {
incremental_verify_ich_failed::<Tcx>(prev_index, result); incremental_verify_ich_failed(tcx, prev_index, result);
} }
} }
#[cold] #[cold]
#[inline(never)] #[inline(never)]
fn incremental_verify_ich_not_green<Tcx>(prev_index: SerializedDepNodeIndex) fn incremental_verify_ich_not_green<Tcx>(tcx: Tcx, prev_index: SerializedDepNodeIndex)
where where
Tcx: DepContext, Tcx: DepContext,
{ {
Tcx::with_context(|tcx| { panic!(
panic!( "fingerprint for green query instance not loaded from cache: {:?}",
"fingerprint for green query instance not loaded from cache: {:?}", tcx.dep_graph().data().unwrap().prev_node_of(prev_index)
tcx.dep_graph().data().unwrap().prev_node_of(prev_index) )
)
})
} }
// Note that this is marked #[cold] and intentionally takes `dyn Debug` for `result`, // Note that this is marked #[cold] and intentionally takes `dyn Debug` for `result`,
@ -674,8 +672,11 @@ where
// chew on (and filling up the final binary, too). // chew on (and filling up the final binary, too).
#[cold] #[cold]
#[inline(never)] #[inline(never)]
fn incremental_verify_ich_failed<Tcx>(prev_index: SerializedDepNodeIndex, result: &dyn Debug) fn incremental_verify_ich_failed<Tcx>(
where tcx: Tcx,
prev_index: SerializedDepNodeIndex,
result: &dyn Debug,
) where
Tcx: DepContext, Tcx: DepContext,
{ {
// When we emit an error message and panic, we try to debug-print the `DepNode` // When we emit an error message and panic, we try to debug-print the `DepNode`
@ -690,25 +691,23 @@ where
let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true)); let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
Tcx::with_context(|tcx| { if old_in_panic {
if old_in_panic { tcx.sess().emit_err(crate::error::Reentrant);
tcx.sess().emit_err(crate::error::Reentrant); } else {
let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name {
format!("`cargo clean -p {crate_name}` or `cargo clean`")
} else { } else {
let run_cmd = if let Some(crate_name) = &tcx.sess().opts.crate_name { "`cargo clean`".to_string()
format!("`cargo clean -p {crate_name}` or `cargo clean`") };
} else {
"`cargo clean`".to_string()
};
let dep_node = tcx.dep_graph().data().unwrap().prev_node_of(prev_index); let dep_node = tcx.dep_graph().data().unwrap().prev_node_of(prev_index);
let dep_node = tcx.sess().emit_err(crate::error::IncrementCompilation { let dep_node = tcx.sess().emit_err(crate::error::IncrementCompilation {
run_cmd, run_cmd,
dep_node: format!("{dep_node:?}"), dep_node: format!("{dep_node:?}"),
}); });
panic!("Found unstable fingerprints for {dep_node:?}: {result:?}"); panic!("Found unstable fingerprints for {dep_node:?}: {result:?}");
} }
});
INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic)); INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));
} }