Skip to content

Commit 3fba9a8

Browse files
committed
optimize non-fast-rejected-bounds using sized hierarchy elaboration
1 parent 2cf6bcf commit 3fba9a8

2 files changed

Lines changed: 6 additions & 28 deletions

File tree

‎compiler/rustc_next_trait_solver/src/solve/trait_goals.rs‎

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use rustc_type_ir::solve::{
1010
QueryResultOrRerunNonErased, RerunNonErased, RerunReason, RerunResultExt, SizedTraitKind,
1111
};
1212
use rustc_type_ir::{
13-
self as ty, CallerBoundsIterator, ClausePolarity, ExistentialPredicate, FieldInfo,
14-
IncludeSizedImplicitBounds, Interner, MayBeErased, Movability, Region, TraitClause, TraitRef,
15-
TypeVisitableExt as _, TypingMode, Unnormalized, Upcast as _, elaborate,
13+
self as ty, CallerBoundsIterator, ExistentialPredicate, FieldInfo, IncludeSizedImplicitBounds,
14+
Interner, MayBeErased, Movability, Region, TraitClause, TraitRef, TypeVisitableExt as _,
15+
TypingMode, Unnormalized, Upcast as _, elaborate,
1616
};
1717
use tracing::{debug, instrument, trace, warn};
1818

@@ -137,39 +137,17 @@ where
137137
ecx: &mut EvalCtxt<'_, D>,
138138
goal: Goal<I, Self>,
139139
) -> impl Iterator<Item = I::Clause> {
140-
fn trait_def_id_matches<I: Interner>(
141-
cx: I,
142-
clause_def_id: I::TraitId,
143-
goal_def_id: I::TraitId,
144-
polarity: ClausePolarity,
145-
) -> bool {
146-
clause_def_id == goal_def_id
147-
// PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so
148-
// check for a `MetaSized` supertrait being matched against a `Sized` assumption.
149-
//
150-
// `PointeeSized` bounds are syntactic sugar for a lack of bounds so don't need this.
151-
|| (polarity == ClausePolarity::Positive
152-
&& cx.is_trait_lang_item(clause_def_id, SolverTraitLangItem::Sized)
153-
&& cx.is_trait_lang_item(goal_def_id, SolverTraitLangItem::MetaSized))
154-
}
155-
156140
goal.param_env
157141
.caller_bounds()
158142
.trait_clauses(ecx.cx())
159143
.with_polarity(goal.predicate.polarity)
144+
.for_trait(goal.predicate.def_id())
160145
.filter(move |trait_clause| {
161-
trait_def_id_matches(
162-
ecx.cx(),
163-
trait_clause.def_id(),
164-
goal.predicate.def_id(),
165-
goal.predicate.polarity,
166-
) && DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
146+
DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify(
167147
goal.predicate.trait_ref.args,
168148
trait_clause.skip_binder().trait_ref.args,
169149
)
170150
})
171-
// TODO: allow using for_trait by elaborating the sized hierarchy
172-
// .for_trait(goal.predicate.def_id())
173151
.interned()
174152
.iter()
175153
}

‎compiler/rustc_type_ir/src/flags.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ impl<I: Interner> FlagComputation<I> {
469469
ty::PredicateKind::Ambiguous => {}
470470

471471
ty::PredicateKind::Clause(ty::ClauseKind::CompressedTrait(c)) => {
472-
// NOTE: this is correct as long as compressed trait clauses represnt trait clauses
472+
// NOTE: this is correct as long as compressed trait clauses represent trait clauses
473473
// that don't have generic parameters other than the self_ty, in which case only computing
474474
// flags of the self_ty is correct.
475475
self.add_args(c.self_ty.as_slice());

0 commit comments

Comments
 (0)