Skip to content

Commit 6287f19

Browse files
committed
gate sub_root fast path on -Zdisable-fast-paths
1 parent d9cf1ae commit 6287f19

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
108108

109109
fn pending_obligations(&self) -> PredicateObligations<'tcx>;
110110

111-
/// Returning all pending obligations which reference an inference
112-
/// variable with `_sub_root`.
111+
/// Pending obligations potentially referencing an inference variable whose
112+
/// sub-unification root is `_sub_root`. May be conservative: implementations
113+
/// can return obligations that don't actually reference `_sub_root` (the
114+
/// default just returns everything).
113115
fn pending_obligations_potentially_referencing_sub_root(
114116
&self,
115117
_infcx: &InferCtxt<'tcx>,

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,14 @@ impl<'tcx> ObligationStorage<'tcx> {
8989
.iter()
9090
.filter(|(_, stalled_on)| {
9191
let Some(stalled_on) = stalled_on else { return true };
92-
// Conservative here: if any of its stalled vars are not infer var anymore,
93-
// some unification happened, so this goal is no longer stalled.
94-
// So include it to re-evaluate in the downstream.
92+
// Don't reuse the sub-unification roots cached on `stalled_on`:
93+
// a later sub-unification merge can have changed which root
94+
// each stalled var belongs to, so the cached info can be stale.
95+
// Walk `stalled_vars` and recompute the current root instead.
96+
//
97+
// Conservative here: if a stalled var no longer resolves to an
98+
// infer var, some unification happened, so the goal is no longer
99+
// stalled. Include it to be re-evaluated downstream.
95100
stalled_on.stalled_vars.iter().filter_map(|arg| arg.as_type()).any(
96101
|ty| match *infcx.shallow_resolve(ty).kind() {
97102
ty::Infer(ty::TyVar(tv)) => infcx.sub_unification_table_root_var(tv) == vid,
@@ -303,6 +308,10 @@ where
303308
infcx: &InferCtxt<'tcx>,
304309
vid: ty::TyVid,
305310
) -> PredicateObligations<'tcx> {
311+
// `-Zdisable-fast-paths`: same gate as the other new-solver fast paths.
312+
if infcx.tcx.disable_trait_solver_fast_paths() {
313+
return self.obligations.clone_pending();
314+
}
306315
self.obligations.clone_pending_potentially_referencing_sub_root(infcx, vid)
307316
}
308317

0 commit comments

Comments
 (0)