Skip to content

Commit b0372ea

Browse files
committed
fix 158441 and unify old and new solver code for ty_or_const_infer_var_changed.
1 parent 6c7e4bc commit b0372ea

4 files changed

Lines changed: 13 additions & 36 deletions

File tree

compiler/rustc_infer/src/infer/context.rs

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -132,31 +132,8 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
132132
self.inner.borrow_mut().unwrap_region_constraints().opportunistic_resolve_var(self.tcx, vid)
133133
}
134134

135-
fn is_changed_var(&self, var: TyOrConstInferVar) -> bool {
136-
match var {
137-
TyOrConstInferVar::Ty(vid) => !self
138-
.try_resolve_ty_var_with_root_vid(vid)
139-
.is_err_and(|(root_vid, _)| root_vid == vid),
140-
TyOrConstInferVar::TyInt(vid) => {
141-
let mut inner = self.inner.borrow_mut();
142-
!matches!(
143-
inner.int_unification_table().probe_value(vid),
144-
ty::IntVarValue::Unknown
145-
if inner.int_unification_table().find(vid) == vid
146-
)
147-
}
148-
TyOrConstInferVar::TyFloat(vid) => {
149-
let mut inner = self.inner.borrow_mut();
150-
!matches!(
151-
inner.float_unification_table().probe_value(vid),
152-
ty::FloatVarValue::Unknown
153-
if inner.float_unification_table().find(vid) == vid
154-
)
155-
}
156-
TyOrConstInferVar::Const(vid) => {
157-
!self.try_resolve_const_var(vid).is_err_and(|_| self.root_const_var(vid) == vid)
158-
}
159-
}
135+
fn ty_or_const_infer_var_changed(&self, var: TyOrConstInferVar) -> bool {
136+
self.ty_or_const_infer_var_changed(var)
160137
}
161138

162139
fn next_region_infer(&self) -> ty::Region<'tcx> {

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,8 @@ impl<'tcx> InferCtxt<'tcx> {
12101210
}
12111211

12121212
/// If `TyVar(vid)` resolves to a type, return that type. Else, return the
1213-
/// universe index of `TyVar(vid)`.
1213+
/// universe index of `TyVar(vid)`, along with the root vid, which can be
1214+
/// cheaply found at the same time.
12141215
pub fn try_resolve_ty_var_with_root_vid(
12151216
&self,
12161217
vid: TyVid,
@@ -1576,14 +1577,13 @@ impl<'tcx> InferCtxt<'tcx> {
15761577
#[inline(always)]
15771578
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar) -> bool {
15781579
match infer_var {
1579-
TyOrConstInferVar::Ty(v) => {
1580-
use self::type_variable::TypeVariableValue;
1581-
1582-
// If `inlined_probe` returns a `Known` value, it never equals
1583-
// `ty::Infer(ty::TyVar(v))`.
1584-
match self.inner.borrow_mut().type_variables().inlined_probe(v) {
1585-
TypeVariableValue::Unknown { .. } => false,
1586-
TypeVariableValue::Known { .. } => true,
1580+
TyOrConstInferVar::Ty(vid) => {
1581+
// If `try_resolve_ty_var` returns `Err`, *and* the `root_vid` is unchanged,
1582+
// it's definitely unchanged. The check against `root_vid` matters, see
1583+
// https://github.com/rust-lang/rust/issues/158441
1584+
match self.try_resolve_ty_var_with_root_vid(vid) {
1585+
Ok(_) => true,
1586+
Err((root_vid, _)) => root_vid != vid,
15871587
}
15881588
}
15891589

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/fast_path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ where
5151

5252
// If any of the stalled goal's generic arguments changed,
5353
// rerunning might make progress so we should rerun.
54-
if stalled_vars.iter().any(|value| delegate.is_changed_var(*value)) {
54+
if stalled_vars.iter().any(|value| delegate.ty_or_const_infer_var_changed(*value)) {
5555
return MayMakeProgress;
5656
}
5757

compiler/rustc_type_ir/src/infer_ctxt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ pub trait InferCtxtLike: Sized {
391391
vid: ty::RegionVid,
392392
) -> <Self::Interner as Interner>::Region;
393393

394-
fn is_changed_var(&self, var: TyOrConstInferVar) -> bool;
394+
fn ty_or_const_infer_var_changed(&self, var: TyOrConstInferVar) -> bool;
395395

396396
fn next_region_infer(&self) -> <Self::Interner as Interner>::Region;
397397
fn next_ty_infer(&self) -> <Self::Interner as Interner>::Ty;

0 commit comments

Comments
 (0)