Apply impl_super_outlives optimization to new trait solver

This commit is contained in:
Michael Goulet
2025-06-19 21:03:10 +00:00
parent 8de4c7234d
commit 24ea06cbe8
3 changed files with 20 additions and 9 deletions

View File

@@ -432,6 +432,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
self.explicit_implied_predicates_of(def_id).map_bound(|preds| preds.into_iter().copied()) self.explicit_implied_predicates_of(def_id).map_bound(|preds| preds.into_iter().copied())
} }
fn impl_super_outlives(
self,
impl_def_id: DefId,
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
self.impl_super_outlives(impl_def_id)
}
fn impl_is_const(self, def_id: DefId) -> bool { fn impl_is_const(self, def_id: DefId) -> bool {
debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true }); debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true });
self.is_conditionally_const(def_id) self.is_conditionally_const(def_id)

View File

@@ -103,15 +103,12 @@ where
// We currently elaborate all supertrait outlives obligations from impls. // We currently elaborate all supertrait outlives obligations from impls.
// This can be removed when we actually do coinduction correctly, and prove // This can be removed when we actually do coinduction correctly, and prove
// all supertrait obligations unconditionally. // all supertrait obligations unconditionally.
let goal_clause: I::Clause = goal.predicate.upcast(cx); ecx.add_goals(
for clause in elaborate::elaborate(cx, [goal_clause]) { GoalSource::Misc,
if matches!( cx.impl_super_outlives(impl_def_id)
clause.kind().skip_binder(), .iter_instantiated(cx, impl_args)
ty::ClauseKind::TypeOutlives(..) | ty::ClauseKind::RegionOutlives(..) .map(|pred| goal.with(cx, pred)),
) { );
ecx.add_goal(GoalSource::Misc, goal.with(cx, clause));
}
}
ecx.evaluate_added_goals_and_make_canonical_response(maximal_certainty) ecx.evaluate_added_goals_and_make_canonical_response(maximal_certainty)
}) })

View File

@@ -271,6 +271,13 @@ pub trait Interner:
def_id: Self::DefId, def_id: Self::DefId,
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>; ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>;
/// This is equivalent to computing the super-predicates of the trait for this impl
/// and filtering them to the outlives predicates. This is purely for performance.
fn impl_super_outlives(
self,
impl_def_id: Self::DefId,
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
fn impl_is_const(self, def_id: Self::DefId) -> bool; fn impl_is_const(self, def_id: Self::DefId) -> bool;
fn fn_is_const(self, def_id: Self::DefId) -> bool; fn fn_is_const(self, def_id: Self::DefId) -> bool;
fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool; fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool;