Use new solver during selection
This commit is contained in:
parent
c62665e09c
commit
9b5a2a4a48
1 changed files with 43 additions and 14 deletions
|
@ -38,6 +38,8 @@ use rustc_errors::Diagnostic;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
use rustc_hir::def_id::DefId;
|
use rustc_hir::def_id::DefId;
|
||||||
use rustc_infer::infer::LateBoundRegionConversionTime;
|
use rustc_infer::infer::LateBoundRegionConversionTime;
|
||||||
|
use rustc_infer::traits::TraitEngine;
|
||||||
|
use rustc_infer::traits::TraitEngineExt;
|
||||||
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
|
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
|
||||||
use rustc_middle::mir::interpret::ErrorHandled;
|
use rustc_middle::mir::interpret::ErrorHandled;
|
||||||
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
|
||||||
|
@ -47,6 +49,7 @@ use rustc_middle::ty::relate::TypeRelation;
|
||||||
use rustc_middle::ty::SubstsRef;
|
use rustc_middle::ty::SubstsRef;
|
||||||
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
|
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
|
||||||
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitable};
|
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitable};
|
||||||
|
use rustc_session::config::TraitSolver;
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
|
|
||||||
use std::cell::{Cell, RefCell};
|
use std::cell::{Cell, RefCell};
|
||||||
|
@ -544,10 +547,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
) -> Result<EvaluationResult, OverflowError> {
|
) -> Result<EvaluationResult, OverflowError> {
|
||||||
self.evaluation_probe(|this| {
|
self.evaluation_probe(|this| {
|
||||||
|
if this.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
|
||||||
this.evaluate_predicate_recursively(
|
this.evaluate_predicate_recursively(
|
||||||
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
|
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
|
||||||
obligation.clone(),
|
obligation.clone(),
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -586,6 +593,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
where
|
where
|
||||||
I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
|
I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
|
||||||
{
|
{
|
||||||
|
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
|
||||||
let mut result = EvaluatedToOk;
|
let mut result = EvaluatedToOk;
|
||||||
for obligation in predicates {
|
for obligation in predicates {
|
||||||
let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
|
let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
|
||||||
|
@ -598,6 +606,27 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
} else {
|
||||||
|
self.evaluate_predicates_recursively_in_new_solver(predicates)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Evaluates the predicates using the new solver when `-Ztrait-solver=next` is enabled
|
||||||
|
fn evaluate_predicates_recursively_in_new_solver(
|
||||||
|
&mut self,
|
||||||
|
predicates: impl IntoIterator<Item = PredicateObligation<'tcx>>,
|
||||||
|
) -> Result<EvaluationResult, OverflowError> {
|
||||||
|
let mut fulfill_cx = crate::solve::FulfillmentCtxt::new();
|
||||||
|
fulfill_cx.register_predicate_obligations(self.infcx, predicates);
|
||||||
|
// True errors
|
||||||
|
if !fulfill_cx.select_where_possible(self.infcx).is_empty() {
|
||||||
|
return Ok(EvaluatedToErr);
|
||||||
|
}
|
||||||
|
if !fulfill_cx.select_all_or_error(self.infcx).is_empty() {
|
||||||
|
return Ok(EvaluatedToAmbig);
|
||||||
|
}
|
||||||
|
// Regions and opaques are handled in the `evaluation_probe` by looking at the snapshot
|
||||||
|
Ok(EvaluatedToOk)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(
|
#[instrument(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue