Rollup merge of #119613 - gavinleroy:expose-obligations, r=lcnr
Expose Obligations created during type inference. This PR is a first pass at exposing the trait obligations generated and solved for during the type-check progress. Exposing these obligations allows for rustc plugins to use the public interface for proof trees (provided by the next gen trait solver). The changes proposed track *all* obligations during the type-check process, this is desirable to not only look at the trees of failed obligations, but also those of successfully proved obligations. This feature is placed behind an unstable compiler option `track-trait-obligations` which should be used together with the `next-solver` option. I should note that the main interface is the function `inspect_typeck` made public in `rustc_hir_typeck/src/lib.rs` which allows the caller to provide a callback granting access to the `FnCtxt`. r? `@lcnr`
This commit is contained in:
commit
2de5ca25d2
5 changed files with 121 additions and 64 deletions
|
@ -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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1718,6 +1723,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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue