Skip to content

Commit af32e33

Browse files
committed
fewer internments in trait solver
1 parent a7ef4d5 commit af32e33

4 files changed

Lines changed: 40 additions & 21 deletions

File tree

‎compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ where
180180
fn probe_and_consider_param_env_candidate(
181181
ecx: &mut EvalCtxt<'_, D>,
182182
goal: Goal<I, Self>,
183-
assumption: I::Clause,
183+
assumption: ty::Binder<I, ty::ClauseKind<I>>,
184184
) -> Result<Result<Candidate<I>, CandidateHeadUsages>, RerunNonErased> {
185185
// Dealing with `ParamEnv` candidates is a bit of a mess as we need to lazily
186186
// check whether the candidate is global while considering normalization.
@@ -229,7 +229,7 @@ where
229229
Self::fast_reject_assumption(ecx, goal, assumption)?;
230230

231231
ecx.probe_trait_candidate(source)
232-
.enter(|ecx| Self::match_assumption(ecx, goal, assumption, then))
232+
.enter(|ecx| Self::match_assumption(ecx, goal, assumption.kind(), then))
233233
}
234234

235235
/// Try to reject the assumption based off of simple heuristics, such as [`ty::ClauseKind`]
@@ -243,13 +243,13 @@ where
243243
fn non_fast_rejected_caller_bounds(
244244
ecx: &mut EvalCtxt<'_, D>,
245245
goal: Goal<I, Self>,
246-
) -> impl Iterator<Item = I::Clause>;
246+
) -> impl Iterator<Item = ty::Binder<I, ty::ClauseKind<I>>>;
247247

248248
/// Relate the goal and assumption.
249249
fn match_assumption(
250250
ecx: &mut EvalCtxt<'_, D>,
251251
goal: Goal<I, Self>,
252-
assumption: I::Clause,
252+
assumption: ty::Binder<I, ty::ClauseKind<I>>,
253253
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
254254
) -> QueryResultOrRerunNonErased<I>;
255255

@@ -1404,7 +1404,7 @@ where
14041404
fn characterize_param_env_assumption(
14051405
&mut self,
14061406
param_env: I::ParamEnv,
1407-
assumption: I::Clause,
1407+
assumption: ty::Binder<I, ty::ClauseKind<I>>,
14081408
) -> Result<(CandidateSource<I>, Certainty), NoSolution> {
14091409
// FIXME: This should be fixed, but it also requires changing the behavior
14101410
// in the old solver which is currently relied on.

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ where
4141
fn non_fast_rejected_caller_bounds(
4242
ecx: &mut EvalCtxt<'_, D>,
4343
goal: Goal<I, Self>,
44-
) -> impl Iterator<Item = I::Clause> {
45-
goal.param_env.caller_bounds().non_trait_clauses().iter().filter(move |&assumption| {
44+
) -> impl Iterator<Item = ty::Binder<I, ty::ClauseKind<I>>> {
45+
goal.param_env.caller_bounds().non_trait_clauses().iter().filter_map(move |assumption| {
4646
match Self::fast_reject_assumption(ecx, goal, assumption) {
47-
Ok(()) => true,
48-
Err(NoSolution) => false,
47+
Ok(()) => Some(assumption.kind()),
48+
Err(NoSolution) => None,
4949
}
5050
})
5151
}
@@ -71,10 +71,16 @@ where
7171
fn match_assumption(
7272
ecx: &mut EvalCtxt<'_, D>,
7373
goal: Goal<I, Self>,
74-
assumption: I::Clause,
74+
assumption: ty::Binder<I, ty::ClauseKind<I>>,
7575
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
7676
) -> QueryResultOrRerunNonErased<I> {
77-
let host_clause = assumption.as_host_effect_clause().unwrap();
77+
let host_clause = assumption
78+
.map_bound(|i| match i {
79+
ty::ClauseKind::HostEffect(h) => Some(h),
80+
_ => None,
81+
})
82+
.transpose()
83+
.unwrap();
7884

7985
let assumption_trait_pred = ecx.instantiate_binder_with_infer(host_clause);
8086
ecx.eq(goal.param_env, goal.predicate.trait_ref, assumption_trait_pred.trait_ref)?;

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,11 @@ where
183183
fn non_fast_rejected_caller_bounds(
184184
ecx: &mut EvalCtxt<'_, D>,
185185
goal: Goal<I, Self>,
186-
) -> impl Iterator<Item = I::Clause> {
187-
goal.param_env.caller_bounds().non_trait_clauses().iter().filter(move |&assumption| {
186+
) -> impl Iterator<Item = ty::Binder<I, ty::ClauseKind<I>>> {
187+
goal.param_env.caller_bounds().non_trait_clauses().iter().filter_map(move |assumption| {
188188
match Self::fast_reject_assumption(ecx, goal, assumption) {
189-
Ok(()) => true,
190-
Err(NoSolution) => false,
189+
Ok(()) => Some(assumption.kind()),
190+
Err(NoSolution) => None,
191191
}
192192
})
193193
}
@@ -218,11 +218,18 @@ where
218218
fn match_assumption(
219219
ecx: &mut EvalCtxt<'_, D>,
220220
goal: Goal<I, Self>,
221-
assumption: I::Clause,
221+
assumption: ty::Binder<I, ty::ClauseKind<I>>,
222222
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
223223
) -> QueryResultOrRerunNonErased<I> {
224224
let cx = ecx.cx();
225-
let projection_pred = assumption.as_projection_clause().unwrap();
225+
let projection_pred = assumption
226+
.map_bound(|i| match i {
227+
ty::ClauseKind::Projection(p) => Some(p),
228+
_ => None,
229+
})
230+
.transpose()
231+
.unwrap();
232+
226233
let assumption_projection_pred = ecx.instantiate_binder_with_infer(projection_pred);
227234
ecx.eq(goal.param_env, goal.predicate.alias, assumption_projection_pred.projection_term)?;
228235

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ where
136136
fn non_fast_rejected_caller_bounds(
137137
ecx: &mut EvalCtxt<'_, D>,
138138
goal: Goal<I, Self>,
139-
) -> impl Iterator<Item = I::Clause> {
139+
) -> impl Iterator<Item = ty::Binder<I, ty::ClauseKind<I>>> {
140140
goal.param_env
141141
.caller_bounds()
142142
.trait_clauses(ecx.cx())
@@ -148,8 +148,8 @@ where
148148
trait_clause.skip_binder().trait_ref.args,
149149
)
150150
})
151-
.interned()
152151
.iter()
152+
.map(|i| i.map_bound(|x| ty::ClauseKind::Trait(x)))
153153
}
154154

155155
fn fast_reject_assumption(
@@ -174,10 +174,16 @@ where
174174
fn match_assumption(
175175
ecx: &mut EvalCtxt<'_, D>,
176176
goal: Goal<I, Self>,
177-
assumption: I::Clause,
177+
assumption: ty::Binder<I, ty::ClauseKind<I>>,
178178
then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased<I>,
179179
) -> QueryResultOrRerunNonErased<I> {
180-
let trait_clause = assumption.as_trait_clause().unwrap();
180+
let trait_clause = assumption
181+
.map_bound(|i| match i {
182+
ty::ClauseKind::Trait(t) => Some(t),
183+
_ => None,
184+
})
185+
.transpose()
186+
.unwrap();
181187

182188
let assumption_trait_pred = ecx.instantiate_binder_with_infer(trait_clause);
183189
ecx.eq(goal.param_env, goal.predicate.trait_ref, assumption_trait_pred.trait_ref)?;

0 commit comments

Comments
 (0)