1
Fork 0

Add trait obligation tracking to FulfillCtxt and expose FnCtxt in rustc_infer using callback.

Pass each obligation to an fn callback with its respective inference context. This avoids needing to keep around copies of obligations or inference contexts.

Specify usability of inspect_typeck in comment.
This commit is contained in:
Gavin Gray 2023-11-21 20:37:36 +01:00 committed by gavinleroy
parent 2457c028c9
commit 130b7e713e
5 changed files with 121 additions and 64 deletions

View file

@ -13,7 +13,9 @@ use rustc_middle::infer::unify_key::{ConstVidKey, EffectVidKey};
use self::opaque_types::OpaqueTypeStorage;
pub(crate) use self::undo_log::{InferCtxtUndoLogs, Snapshot, UndoLog};
use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine, TraitEngineExt};
use crate::traits::{
self, ObligationCause, ObligationInspector, PredicateObligations, TraitEngine, TraitEngineExt,
};
use rustc_data_structures::fx::FxIndexMap;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -334,6 +336,8 @@ pub struct InferCtxt<'tcx> {
pub intercrate: bool,
next_trait_solver: bool,
pub obligation_inspector: Cell<Option<ObligationInspector<'tcx>>>,
}
impl<'tcx> ty::InferCtxtLike for InferCtxt<'tcx> {
@ -708,6 +712,7 @@ impl<'tcx> InferCtxtBuilder<'tcx> {
universe: Cell::new(ty::UniverseIndex::ROOT),
intercrate,
next_trait_solver,
obligation_inspector: Cell::new(None),
}
}
}
@ -1724,6 +1729,15 @@ impl<'tcx> InferCtxt<'tcx> {
}
}
}
/// Attach a callback to be invoked on each root obligation evaluated in the new trait solver.
pub fn attach_obligation_inspector(&self, inspector: ObligationInspector<'tcx>) {
debug_assert!(
self.obligation_inspector.get().is_none(),
"shouldn't override a set obligation inspector"
);
self.obligation_inspector.set(Some(inspector));
}
}
impl<'tcx> TypeErrCtxt<'_, 'tcx> {