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> {
type Implicit<'a> = TyCtxt<'a>;
type DepKind = DepKind;
#[inline]
@ -79,11 +78,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
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]
fn dep_graph(&self) -> &DepGraph {
&self.dep_graph

View File

@ -23,15 +23,11 @@ use std::{fmt, panic};
use self::graph::{print_markframe_trace, MarkFrame};
pub trait DepContext: Copy {
type Implicit<'a>: DepContext;
type DepKind: self::DepKind;
/// Create a hashing context for hashing new results.
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.
fn dep_graph(&self) -> &DepGraph<Self::DepKind>;

View File

@ -641,7 +641,7 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
Tcx: DepContext,
{
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| {
@ -651,22 +651,20 @@ pub(crate) fn incremental_verify_ich<Tcx, V: Debug>(
let old_hash = dep_graph_data.prev_fingerprint_of(prev_index);
if new_hash != old_hash {
incremental_verify_ich_failed::<Tcx>(prev_index, result);
incremental_verify_ich_failed(tcx, prev_index, result);
}
}
#[cold]
#[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
Tcx: DepContext,
{
Tcx::with_context(|tcx| {
panic!(
"fingerprint for green query instance not loaded from cache: {:?}",
tcx.dep_graph().data().unwrap().prev_node_of(prev_index)
)
})
}
// 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).
#[cold]
#[inline(never)]
fn incremental_verify_ich_failed<Tcx>(prev_index: SerializedDepNodeIndex, result: &dyn Debug)
where
fn incremental_verify_ich_failed<Tcx>(
tcx: Tcx,
prev_index: SerializedDepNodeIndex,
result: &dyn Debug,
) where
Tcx: DepContext,
{
// When we emit an error message and panic, we try to debug-print the `DepNode`
@ -690,7 +691,6 @@ where
let old_in_panic = INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.replace(true));
Tcx::with_context(|tcx| {
if old_in_panic {
tcx.sess().emit_err(crate::error::Reentrant);
} else {
@ -708,7 +708,6 @@ where
});
panic!("Found unstable fingerprints for {dep_node:?}: {result:?}");
}
});
INSIDE_VERIFY_PANIC.with(|in_panic| in_panic.set(old_in_panic));
}