1
Fork 0

Split -Zchalk flag into -Ztrait-solver=(stock|chalk|next) flag

This commit is contained in:
Michael Goulet 2023-01-02 23:12:47 +00:00
parent df756439df
commit a4974fa9c7
7 changed files with 44 additions and 16 deletions

View file

@ -3,6 +3,7 @@ use std::fmt::Debug;
use super::TraitEngine;
use super::{ChalkFulfillmentContext, FulfillmentContext};
use crate::solve::FulfillmentCtxt as NextFulfillmentCtxt;
use crate::traits::NormalizeExt;
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir::def_id::{DefId, LocalDefId};
@ -20,6 +21,7 @@ use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::ToPredicate;
use rustc_middle::ty::TypeFoldable;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config::TraitSolver;
use rustc_span::Span;
pub trait TraitEngineExt<'tcx> {
@ -29,18 +31,18 @@ pub trait TraitEngineExt<'tcx> {
impl<'tcx> TraitEngineExt<'tcx> for dyn TraitEngine<'tcx> {
fn new(tcx: TyCtxt<'tcx>) -> Box<Self> {
if tcx.sess.opts.unstable_opts.chalk {
Box::new(ChalkFulfillmentContext::new())
} else {
Box::new(FulfillmentContext::new())
match tcx.sess.opts.unstable_opts.trait_solver {
TraitSolver::Stock => Box::new(FulfillmentContext::new()),
TraitSolver::Chalk => Box::new(ChalkFulfillmentContext::new()),
TraitSolver::Next => Box::new(NextFulfillmentCtxt::new()),
}
}
fn new_in_snapshot(tcx: TyCtxt<'tcx>) -> Box<Self> {
if tcx.sess.opts.unstable_opts.chalk {
Box::new(ChalkFulfillmentContext::new_in_snapshot())
} else {
Box::new(FulfillmentContext::new_in_snapshot())
match tcx.sess.opts.unstable_opts.trait_solver {
TraitSolver::Stock => Box::new(FulfillmentContext::new_in_snapshot()),
TraitSolver::Chalk => Box::new(ChalkFulfillmentContext::new_in_snapshot()),
TraitSolver::Next => Box::new(NextFulfillmentCtxt::new()),
}
}
}

View file

@ -40,6 +40,7 @@ use rustc_middle::ty::{
self, SubtypePredicate, ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt, TypeFoldable,
TypeVisitable,
};
use rustc_session::config::TraitSolver;
use rustc_session::Limit;
use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::symbol::sym;
@ -1167,7 +1168,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
}
ty::PredicateKind::WellFormed(ty) => {
if !self.tcx.sess.opts.unstable_opts.chalk {
if self.tcx.sess.opts.unstable_opts.trait_solver != TraitSolver::Chalk {
// WF predicates cannot themselves make
// errors. They can only block due to
// ambiguity; otherwise, they always

View file

@ -15,6 +15,7 @@ use rustc_middle::ty::{
self, Binder, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
ToPolyTraitRef, ToPredicate, TraitRef, Ty, TyCtxt,
};
use rustc_session::config::TraitSolver;
use rustc_span::def_id::DefId;
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};
@ -767,8 +768,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
debug!(?closure_def_id, ?trait_ref, ?nested, "confirm closure candidate obligations");
// FIXME: Chalk
if !self.tcx().sess.opts.unstable_opts.chalk {
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Chalk {
nested.push(obligation.with(
self.tcx(),
ty::Binder::dummy(ty::PredicateKind::ClosureKind(closure_def_id, substs, kind)),