Skip to content

Commit 55ef19c

Browse files
committed
Auto merge of #147111 - BoxyUwU:rename_obligation_processing_apis, r=lcnr
rename `select_where_possible` and `select_all_or_error` r? `@lcnr` I find that people get confused by what these methods do. The verb "select" is not really that helpful and is just a reference to somewhat of an implementation detail of the trait solvers that doesn't even apply to most obligation kinds. I went with `try_evaluate_obligations` and `evaluate_obligations_error_on_ambiguity`. This maintains consistency with the new solvers `evalute_goal` entry point. it's unfortunate that we say obligations rather than goals but this maintains consistency with `register_obligation` functions which I think is a good thing. In the long term possibly we rename `Obligation` or `Goal` 🤷‍♀️
2 parents d4f18cf + e4bbba4 commit 55ef19c

File tree

10 files changed

+23
-23
lines changed

10 files changed

+23
-23
lines changed

crates/hir-ty/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ fn structurally_normalize_ty<'db>(
304304
// evaluate/fulfill mismatches, but that's not a reason for an ICE.
305305
return None;
306306
};
307-
let errors = ocx.select_where_possible();
307+
let errors = ocx.try_evaluate_obligations();
308308
if !errors.is_empty() {
309309
unreachable!();
310310
}

crates/hir-ty/src/infer/coerce.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl<'a, 'b, 'db> Coerce<'a, 'b, 'db> {
160160
Ok(InferOk { value, obligations }) => {
161161
let mut ocx = ObligationCtxt::new(this.infer_ctxt());
162162
ocx.register_obligations(obligations);
163-
if ocx.select_where_possible().is_empty() {
163+
if ocx.try_evaluate_obligations().is_empty() {
164164
Ok(InferOk { value, obligations: ocx.into_pending_obligations() })
165165
} else {
166166
Err(TypeError::Mismatch)
@@ -743,7 +743,7 @@ impl<'a, 'b, 'db> Coerce<'a, 'b, 'db> {
743743
Some(PredicateKind::AliasRelate(..)) => {
744744
let mut ocx = ObligationCtxt::new(self.infer_ctxt());
745745
ocx.register_obligation(obligation);
746-
if !ocx.select_where_possible().is_empty() {
746+
if !ocx.try_evaluate_obligations().is_empty() {
747747
return Err(TypeError::Mismatch);
748748
}
749749
coercion.obligations.extend(ocx.into_pending_obligations());
@@ -1119,7 +1119,7 @@ impl<'db> InferenceContext<'db> {
11191119
prev_ty,
11201120
new_ty,
11211121
)?;
1122-
if ocx.select_where_possible().is_empty() {
1122+
if ocx.try_evaluate_obligations().is_empty() {
11231123
Ok(InferOk { value, obligations: ocx.into_pending_obligations() })
11241124
} else {
11251125
Err(TypeError::Mismatch)

crates/hir-ty/src/infer/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2151,7 +2151,7 @@ impl<'db> InferenceContext<'db> {
21512151
expected_output.to_nextsolver(interner),
21522152
formal_output,
21532153
)?;
2154-
if !ocx.select_where_possible().is_empty() {
2154+
if !ocx.try_evaluate_obligations().is_empty() {
21552155
return Err(crate::next_solver::TypeError::Mismatch);
21562156
}
21572157

crates/hir-ty/src/infer/unify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@ impl<'db> InferenceTable<'db> {
818818
}
819819

820820
pub(crate) fn select_obligations_where_possible(&mut self) {
821-
self.fulfillment_cx.select_where_possible(&self.infer_ctxt);
821+
self.fulfillment_cx.try_evaluate_obligations(&self.infer_ctxt);
822822
}
823823

824824
pub(super) fn register_predicate(

crates/hir-ty/src/method_resolution.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,7 +1785,7 @@ fn is_valid_trait_method_candidate(
17851785
let mut ctxt = ObligationCtxt::new(&table.infer_ctxt);
17861786
ctxt.register_obligations(infer_ok.into_obligations());
17871787
// FIXME: Are we doing this correctly? Probably better to follow rustc more closely.
1788-
check_that!(ctxt.select_where_possible().is_empty());
1788+
check_that!(ctxt.try_evaluate_obligations().is_empty());
17891789
}
17901790

17911791
check_that!(table.unify(receiver_ty, &expected_receiver));
@@ -1871,7 +1871,7 @@ fn is_valid_impl_fn_candidate(
18711871
)
18721872
}));
18731873

1874-
if ctxt.select_where_possible().is_empty() {
1874+
if ctxt.try_evaluate_obligations().is_empty() {
18751875
IsValidCandidate::Yes
18761876
} else {
18771877
IsValidCandidate::No

crates/hir-ty/src/next_solver/fulfill.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct ObligationStorage<'db> {
5454
/// Obligations which resulted in an overflow in fulfillment itself.
5555
///
5656
/// We cannot eagerly return these as error so we instead store them here
57-
/// to avoid recomputing them each time `select_where_possible` is called.
57+
/// to avoid recomputing them each time `try_evaluate_obligations` is called.
5858
/// This also allows us to return the correct `FulfillmentError` for them.
5959
overflowed: Vec<PredicateObligation<'db>>,
6060
pending: PendingObligations<'db>,
@@ -95,7 +95,7 @@ impl<'db> ObligationStorage<'db> {
9595
// IMPORTANT: we must not use solve any inference variables in the obligations
9696
// as this is all happening inside of a probe. We use a probe to make sure
9797
// we get all obligations involved in the overflow. We pretty much check: if
98-
// we were to do another step of `select_where_possible`, which goals would
98+
// we were to do another step of `try_evaluate_obligations`, which goals would
9999
// change.
100100
// FIXME: <https://github.com/Gankra/thin-vec/pull/66> is merged, this can be removed.
101101
self.overflowed.extend(
@@ -131,7 +131,7 @@ impl<'db> FulfillmentCtxt<'db> {
131131
infcx: &InferCtxt<'db>,
132132
obligation: PredicateObligation<'db>,
133133
) {
134-
// FIXME: See the comment in `select_where_possible()`.
134+
// FIXME: See the comment in `try_evaluate_obligations()`.
135135
// assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots());
136136
self.obligations.register(obligation, None);
137137
}
@@ -141,7 +141,7 @@ impl<'db> FulfillmentCtxt<'db> {
141141
infcx: &InferCtxt<'db>,
142142
obligations: impl IntoIterator<Item = PredicateObligation<'db>>,
143143
) {
144-
// FIXME: See the comment in `select_where_possible()`.
144+
// FIXME: See the comment in `try_evaluate_obligations()`.
145145
// assert_eq!(self.usable_in_snapshot, infcx.num_open_snapshots());
146146
obligations.into_iter().for_each(|obligation| self.obligations.register(obligation, None));
147147
}
@@ -158,7 +158,7 @@ impl<'db> FulfillmentCtxt<'db> {
158158
.collect()
159159
}
160160

161-
pub(crate) fn select_where_possible(
161+
pub(crate) fn try_evaluate_obligations(
162162
&mut self,
163163
infcx: &InferCtxt<'db>,
164164
) -> Vec<NextSolverError<'db>> {
@@ -223,11 +223,11 @@ impl<'db> FulfillmentCtxt<'db> {
223223
errors
224224
}
225225

226-
pub(crate) fn select_all_or_error(
226+
pub(crate) fn evaluate_obligations_error_on_ambiguity(
227227
&mut self,
228228
infcx: &InferCtxt<'db>,
229229
) -> Vec<NextSolverError<'db>> {
230-
let errors = self.select_where_possible(infcx);
230+
let errors = self.try_evaluate_obligations(infcx);
231231
if !errors.is_empty() {
232232
return errors;
233233
}

crates/hir-ty/src/next_solver/inspect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'db> NormalizesToTermHack<'db> {
9292
let mut ocx = ObligationCtxt::new(infcx);
9393
ocx.eq(&ObligationCause::dummy(), param_env, self.term, self.unconstrained_term)?;
9494
f(&mut ocx);
95-
let errors = ocx.select_all_or_error();
95+
let errors = ocx.evaluate_obligations_error_on_ambiguity();
9696
if errors.is_empty() {
9797
Ok(Certainty::Yes)
9898
} else if errors.iter().all(|e| !matches!(e, NextSolverError::TrueError(_))) {

crates/hir-ty/src/next_solver/normalize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ where
7777
stalled_coroutine_goals: vec![],
7878
};
7979
let value = value.try_fold_with(&mut folder)?;
80-
let errors = folder.fulfill_cx.select_all_or_error(at.infcx);
80+
let errors = folder.fulfill_cx.evaluate_obligations_error_on_ambiguity(at.infcx);
8181
if errors.is_empty() { Ok((value, folder.stalled_coroutine_goals)) } else { Err(errors) }
8282
}
8383

@@ -138,7 +138,7 @@ impl<'db> NormalizationFolder<'_, 'db> {
138138
fn select_all_and_stall_coroutine_predicates(
139139
&mut self,
140140
) -> Result<(), Vec<NextSolverError<'db>>> {
141-
let errors = self.fulfill_cx.select_where_possible(self.at.infcx);
141+
let errors = self.fulfill_cx.try_evaluate_obligations(self.at.infcx);
142142
if !errors.is_empty() {
143143
return Err(errors);
144144
}

crates/hir-ty/src/next_solver/obligation_ctxt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ impl<'a, 'db> ObligationCtxt<'a, 'db> {
144144
}
145145

146146
#[must_use]
147-
pub fn select_where_possible(&mut self) -> Vec<NextSolverError<'db>> {
148-
self.engine.select_where_possible(self.infcx)
147+
pub fn try_evaluate_obligations(&mut self) -> Vec<NextSolverError<'db>> {
148+
self.engine.try_evaluate_obligations(self.infcx)
149149
}
150150

151151
#[must_use]
152-
pub fn select_all_or_error(&mut self) -> Vec<NextSolverError<'db>> {
153-
self.engine.select_all_or_error(self.infcx)
152+
pub fn evaluate_obligations_error_on_ambiguity(&mut self) -> Vec<NextSolverError<'db>> {
153+
self.engine.evaluate_obligations_error_on_ambiguity(self.infcx)
154154
}
155155

156156
/// Returns the not-yet-processed and stalled obligations from the

crates/hir-ty/src/next_solver/structural_normalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl<'db> At<'_, 'db> {
4747
);
4848

4949
fulfill_cx.register_predicate_obligation(self.infcx, obligation);
50-
let errors = fulfill_cx.select_where_possible(self.infcx);
50+
let errors = fulfill_cx.try_evaluate_obligations(self.infcx);
5151
if !errors.is_empty() {
5252
return Err(errors);
5353
}

0 commit comments

Comments
 (0)