Skip to content

Apply impl_super_outlives optimization to new trait solver #142746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
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 {
debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true });
self.is_conditionally_const(def_id)
Expand Down
15 changes: 6 additions & 9 deletions compiler/rustc_next_trait_solver/src/solve/trait_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,12 @@ where
// We currently elaborate all supertrait outlives obligations from impls.
// This can be removed when we actually do coinduction correctly, and prove
// all supertrait obligations unconditionally.
let goal_clause: I::Clause = goal.predicate.upcast(cx);
for clause in elaborate::elaborate(cx, [goal_clause]) {
if matches!(
clause.kind().skip_binder(),
ty::ClauseKind::TypeOutlives(..) | ty::ClauseKind::RegionOutlives(..)
) {
ecx.add_goal(GoalSource::Misc, goal.with(cx, clause));
}
}
ecx.add_goals(
GoalSource::Misc,
cx.impl_super_outlives(impl_def_id)
.iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred)),
);

ecx.evaluate_added_goals_and_make_canonical_response(maximal_certainty)
})
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_type_ir/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ pub trait Interner:
def_id: Self::DefId,
) -> 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 fn_is_const(self, def_id: Self::DefId) -> bool;
fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool;
Expand Down
Loading