Skip to content

Commit 0b002eb

Browse files
authored
Rollup merge of rust-lang#112122 - compiler-errors:next-coherence, r=lcnr
Add `-Ztrait-solver=next-coherence` Flag that conditionally uses the trait solver *only* during coherence, for more testing and/or eventual partial-migration onto the trait solver (in the medium- to long-term). * This still uses the selection context in some of the coherence methods I think, so it's not "complete". Putting this up for review and/or for further work in-tree. * I probably need to spend a bit more time making sure that we don't sneakily create any other infcx's during coherence that also need the new solver enabled. r? `@lcnr`
2 parents cbe429c + aabdeed commit 0b002eb

File tree

35 files changed

+142
-63
lines changed

35 files changed

+142
-63
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
285285
let infcx = self
286286
.tcx
287287
.infer_ctxt()
288-
.with_opaque_type_inference(if self.tcx.trait_solver_next() {
288+
.with_opaque_type_inference(if self.next_trait_solver() {
289289
DefiningAnchor::Bind(def_id)
290290
} else {
291291
DefiningAnchor::Bubble

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
188188

189189
// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
190190
// predefined opaques in the typeck root.
191-
if infcx.tcx.trait_solver_next() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
191+
if infcx.next_trait_solver() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
192192
checker.register_predefined_opaques_in_new_solver();
193193
}
194194

compiler/rustc_hir_analysis/src/autoderef.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
7373
// NOTE: we may still need to normalize the built-in deref in case
7474
// we have some type like `&<Ty as Trait>::Assoc`, since users of
7575
// autoderef expect this type to have been structurally normalized.
76-
if self.infcx.tcx.trait_solver_next()
76+
if self.infcx.next_trait_solver()
7777
&& let ty::Alias(ty::Projection, _) = ty.kind()
7878
{
7979
let (normalized_ty, obligations) = self.structurally_normalize(ty)?;
@@ -161,8 +161,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
161161
&self,
162162
ty: Ty<'tcx>,
163163
) -> Option<(Ty<'tcx>, Vec<traits::PredicateObligation<'tcx>>)> {
164-
let tcx = self.infcx.tcx;
165-
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(tcx);
164+
let mut fulfill_cx = <dyn TraitEngine<'tcx>>::new_in_snapshot(self.infcx);
166165

167166
let cause = traits::ObligationCause::misc(self.span, self.body_id);
168167
let normalized_ty = match self

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1549,7 +1549,7 @@ pub(super) fn check_generator_obligations(tcx: TyCtxt<'_>, def_id: LocalDefId) {
15491549
.with_opaque_type_inference(DefiningAnchor::Bind(def_id))
15501550
.build();
15511551

1552-
let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(infcx.tcx);
1552+
let mut fulfillment_cx = <dyn TraitEngine<'_>>::new(&infcx);
15531553
for (predicate, cause) in generator_interior_predicates {
15541554
let obligation = Obligation::new(tcx, cause.clone(), param_env, *predicate);
15551555
fulfillment_cx.register_predicate_obligation(&infcx, obligation);

compiler/rustc_hir_typeck/src/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
156156
// In the new solver, lazy norm may allow us to shallowly equate
157157
// more types, but we emit possibly impossible-to-satisfy obligations.
158158
// Filter these cases out to make sure our coercion is more accurate.
159-
if self.tcx.trait_solver_next() {
159+
if self.next_trait_solver() {
160160
if let Ok(res) = &res {
161161
for obligation in &res.obligations {
162162
if !self.predicate_may_hold(&obligation) {

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14761476
pub fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx> {
14771477
let mut ty = self.resolve_vars_with_obligations(ty);
14781478

1479-
if self.tcx.trait_solver_next()
1479+
if self.next_trait_solver()
14801480
&& let ty::Alias(ty::Projection, _) = ty.kind()
14811481
{
14821482
match self

compiler/rustc_hir_typeck/src/inherited.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ impl<'tcx> Inherited<'tcx> {
8686

8787
Inherited {
8888
typeck_results,
89+
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(&infcx)),
8990
infcx,
90-
fulfillment_cx: RefCell::new(<dyn TraitEngine<'_>>::new(tcx)),
9191
locals: RefCell::new(Default::default()),
9292
deferred_sized_obligations: RefCell::new(Vec::new()),
9393
deferred_call_resolutions: RefCell::new(Default::default()),

compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
591591
.insert(opaque_type_key, hidden_type)
592592
&& last_opaque_ty.ty != hidden_type.ty
593593
{
594-
assert!(!self.tcx().trait_solver_next());
594+
assert!(!self.fcx.next_trait_solver());
595595
hidden_type
596596
.report_mismatch(&last_opaque_ty, opaque_type_key.def_id, self.tcx())
597597
.stash(
@@ -812,7 +812,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
812812

813813
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
814814
match self.fcx.fully_resolve(t) {
815-
Ok(t) if self.fcx.tcx.trait_solver_next() => {
815+
Ok(t) if self.fcx.next_trait_solver() => {
816816
// We must normalize erasing regions here, since later lints
817817
// expect that types that show up in the typeck are fully
818818
// normalized.

compiler/rustc_infer/src/infer/at.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl<'tcx> InferCtxt<'tcx> {
8282
in_snapshot: self.in_snapshot.clone(),
8383
universe: self.universe.clone(),
8484
intercrate: self.intercrate,
85+
next_trait_solver: self.next_trait_solver,
8586
}
8687
}
8788
}

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ impl<'tcx> InferCtxt<'tcx> {
109109
| (
110110
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)),
111111
ty::Alias(AliasKind::Projection, _),
112-
) if self.tcx.trait_solver_next() => {
112+
) if self.next_trait_solver() => {
113113
bug!()
114114
}
115115

116-
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.tcx.trait_solver_next() => {
116+
(_, ty::Alias(..)) | (ty::Alias(..), _) if self.next_trait_solver() => {
117117
relation.register_type_relate_obligation(a, b);
118118
Ok(a)
119119
}
@@ -227,9 +227,20 @@ impl<'tcx> InferCtxt<'tcx> {
227227
return self.unify_const_variable(vid, a, relation.param_env());
228228
}
229229
(ty::ConstKind::Unevaluated(..), _) | (_, ty::ConstKind::Unevaluated(..))
230-
if self.tcx.features().generic_const_exprs || self.tcx.trait_solver_next() =>
230+
if self.tcx.features().generic_const_exprs || self.next_trait_solver() =>
231231
{
232-
relation.register_const_equate_obligation(a, b);
232+
let (a, b) = if relation.a_is_expected() { (a, b) } else { (b, a) };
233+
234+
relation.register_predicates([ty::Binder::dummy(if self.next_trait_solver() {
235+
ty::PredicateKind::AliasRelate(
236+
a.into(),
237+
b.into(),
238+
ty::AliasRelationDirection::Equate,
239+
)
240+
} else {
241+
ty::PredicateKind::ConstEquate(a, b)
242+
})]);
243+
233244
return Ok(b);
234245
}
235246
_ => {}
@@ -453,19 +464,6 @@ pub trait ObligationEmittingRelation<'tcx>: TypeRelation<'tcx> {
453464
/// be used if control over the obligation causes is required.
454465
fn register_predicates(&mut self, obligations: impl IntoIterator<Item: ToPredicate<'tcx>>);
455466

456-
/// Register an obligation that both constants must be equal to each other.
457-
///
458-
/// If they aren't equal then the relation doesn't hold.
459-
fn register_const_equate_obligation(&mut self, a: ty::Const<'tcx>, b: ty::Const<'tcx>) {
460-
let (a, b) = if self.a_is_expected() { (a, b) } else { (b, a) };
461-
462-
self.register_predicates([ty::Binder::dummy(if self.tcx().trait_solver_next() {
463-
ty::PredicateKind::AliasRelate(a.into(), b.into(), ty::AliasRelationDirection::Equate)
464-
} else {
465-
ty::PredicateKind::ConstEquate(a, b)
466-
})]);
467-
}
468-
469467
/// Register an obligation that both types must be related to each other according to
470468
/// the [`ty::AliasRelationDirection`] given by [`ObligationEmittingRelation::alias_relate_direction`]
471469
fn register_type_relate_obligation(&mut self, a: Ty<'tcx>, b: Ty<'tcx>) {

0 commit comments

Comments
 (0)