1
Fork 0

Opt-in diagnostics reporting to avoid doing extra work in the new solver

This commit is contained in:
Michael Goulet 2024-06-01 14:51:31 -04:00
parent 54b2b7d460
commit eb0a70a557
31 changed files with 200 additions and 107 deletions

View file

@ -50,7 +50,8 @@ pub fn codegen_select_candidate<'tcx>(
// Currently, we use a fulfillment context to completely resolve
// all nested obligations. This is because they can inform the
// inference of the impl's type parameters.
let ocx = ObligationCtxt::new(&infcx);
// FIXME(-Znext-solver): Doesn't need diagnostics if new solver.
let ocx = ObligationCtxt::new_with_diagnostics(&infcx);
let impl_source = selection.map(|obligation| {
ocx.register_obligation(obligation);
});

View file

@ -8,7 +8,7 @@ use rustc_trait_selection::traits::query::{
normalize::NormalizationResult, CanonicalAliasGoal, NoSolution,
};
use rustc_trait_selection::traits::{
self, FulfillmentErrorCode, ObligationCause, SelectionContext,
self, FulfillmentError, FulfillmentErrorCode, ObligationCause, ObligationCtxt, SelectionContext,
};
use tracing::debug;
@ -29,7 +29,8 @@ fn normalize_canonicalized_projection_ty<'tcx>(
tcx.infer_ctxt().enter_canonical_trait_query(
&goal,
|ocx, ParamEnvAnd { param_env, value: goal }| {
|ocx: &ObligationCtxt<'_, 'tcx, FulfillmentError<'tcx>>,
ParamEnvAnd { param_env, value: goal }| {
debug_assert!(!ocx.infcx.next_trait_solver());
let selcx = &mut SelectionContext::new(ocx.infcx);
let cause = ObligationCause::dummy();
@ -73,7 +74,7 @@ fn normalize_canonicalized_weak_ty<'tcx>(
tcx.infer_ctxt().enter_canonical_trait_query(
&goal,
|ocx, ParamEnvAnd { param_env, value: goal }| {
|ocx: &ObligationCtxt<'_, 'tcx>, ParamEnvAnd { param_env, value: goal }| {
let obligations = tcx.predicates_of(goal.def_id).instantiate_own(tcx, goal.args).map(
|(predicate, span)| {
traits::Obligation::new(
@ -99,7 +100,7 @@ fn normalize_canonicalized_inherent_projection_ty<'tcx>(
tcx.infer_ctxt().enter_canonical_trait_query(
&goal,
|ocx, ParamEnvAnd { param_env, value: goal }| {
|ocx: &ObligationCtxt<'_, 'tcx>, ParamEnvAnd { param_env, value: goal }| {
let selcx = &mut SelectionContext::new(ocx.infcx);
let cause = ObligationCause::dummy();
let mut obligations = vec![];

View file

@ -43,10 +43,13 @@ fn type_op_eq<'tcx>(
tcx: TyCtxt<'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Eq<'tcx>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |ocx, key| {
let (param_env, Eq { a, b }) = key.into_parts();
Ok(ocx.eq(&ObligationCause::dummy(), param_env, a, b)?)
})
tcx.infer_ctxt().enter_canonical_trait_query(
&canonicalized,
|ocx: &ObligationCtxt<'_, 'tcx>, key| {
let (param_env, Eq { a, b }) = key.into_parts();
Ok(ocx.eq(&ObligationCause::dummy(), param_env, a, b)?)
},
)
}
fn type_op_normalize<'tcx, T>(
@ -95,10 +98,13 @@ fn type_op_subtype<'tcx>(
tcx: TyCtxt<'tcx>,
canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, Subtype<'tcx>>>,
) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> {
tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |ocx, key| {
let (param_env, Subtype { sub, sup }) = key.into_parts();
Ok(ocx.sup(&ObligationCause::dummy(), param_env, sup, sub)?)
})
tcx.infer_ctxt().enter_canonical_trait_query(
&canonicalized,
|ocx: &ObligationCtxt<'_, 'tcx>, key| {
let (param_env, Subtype { sub, sup }) = key.into_parts();
Ok(ocx.sup(&ObligationCause::dummy(), param_env, sup, sub)?)
},
)
}
fn type_op_prove_predicate<'tcx>(