Skip to content

Commit 7b864ac

Browse files
Rollup merge of #142933 - compiler-errors:refactor-solver-api, r=lcnr
Simplify root goal API of solver a bit Root goal API is more easily distinguished between proof tree and non-proof tree, rather than `eval_goal` vs `eval_goal_raw`. r? lcnr
2 parents 010af6a + abd1585 commit 7b864ac

File tree

4 files changed

+41
-68
lines changed

4 files changed

+41
-68
lines changed

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,9 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
147147
fn evaluate_root_goal(
148148
&self,
149149
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
150-
generate_proof_tree: GenerateProofTree,
151150
span: <Self::Interner as Interner>::Span,
152151
stalled_on: Option<GoalStalledOn<Self::Interner>>,
153-
) -> (
154-
Result<GoalEvaluation<Self::Interner>, NoSolution>,
155-
Option<inspect::GoalEvaluation<Self::Interner>>,
156-
);
152+
) -> Result<GoalEvaluation<Self::Interner>, NoSolution>;
157153

158154
/// Check whether evaluating `goal` with a depth of `root_depth` may
159155
/// succeed. This only returns `false` if the goal is guaranteed to
@@ -170,17 +166,16 @@ pub trait SolverDelegateEvalExt: SolverDelegate {
170166

171167
// FIXME: This is only exposed because we need to use it in `analyse.rs`
172168
// which is not yet uplifted. Once that's done, we should remove this.
173-
fn evaluate_root_goal_raw(
169+
fn evaluate_root_goal_for_proof_tree(
174170
&self,
175171
goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
176-
generate_proof_tree: GenerateProofTree,
177-
stalled_on: Option<GoalStalledOn<Self::Interner>>,
172+
span: <Self::Interner as Interner>::Span,
178173
) -> (
179174
Result<
180175
(NestedNormalizationGoals<Self::Interner>, GoalEvaluation<Self::Interner>),
181176
NoSolution,
182177
>,
183-
Option<inspect::GoalEvaluation<Self::Interner>>,
178+
inspect::GoalEvaluation<Self::Interner>,
184179
);
185180
}
186181

@@ -193,13 +188,17 @@ where
193188
fn evaluate_root_goal(
194189
&self,
195190
goal: Goal<I, I::Predicate>,
196-
generate_proof_tree: GenerateProofTree,
197191
span: I::Span,
198192
stalled_on: Option<GoalStalledOn<I>>,
199-
) -> (Result<GoalEvaluation<I>, NoSolution>, Option<inspect::GoalEvaluation<I>>) {
200-
EvalCtxt::enter_root(self, self.cx().recursion_limit(), generate_proof_tree, span, |ecx| {
201-
ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal, stalled_on)
202-
})
193+
) -> Result<GoalEvaluation<I>, NoSolution> {
194+
EvalCtxt::enter_root(
195+
self,
196+
self.cx().recursion_limit(),
197+
GenerateProofTree::No,
198+
span,
199+
|ecx| ecx.evaluate_goal(GoalEvaluationKind::Root, GoalSource::Misc, goal, stalled_on),
200+
)
201+
.0
203202
}
204203

205204
fn root_goal_may_hold_with_depth(
@@ -217,24 +216,22 @@ where
217216
}
218217

219218
#[instrument(level = "debug", skip(self))]
220-
fn evaluate_root_goal_raw(
219+
fn evaluate_root_goal_for_proof_tree(
221220
&self,
222221
goal: Goal<I, I::Predicate>,
223-
generate_proof_tree: GenerateProofTree,
224-
stalled_on: Option<GoalStalledOn<I>>,
222+
span: I::Span,
225223
) -> (
226224
Result<(NestedNormalizationGoals<I>, GoalEvaluation<I>), NoSolution>,
227-
Option<inspect::GoalEvaluation<I>>,
225+
inspect::GoalEvaluation<I>,
228226
) {
229-
EvalCtxt::enter_root(
227+
let (result, proof_tree) = EvalCtxt::enter_root(
230228
self,
231229
self.cx().recursion_limit(),
232-
generate_proof_tree,
233-
I::Span::dummy(),
234-
|ecx| {
235-
ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal, stalled_on)
236-
},
237-
)
230+
GenerateProofTree::Yes,
231+
span,
232+
|ecx| ecx.evaluate_goal_raw(GoalEvaluationKind::Root, GoalSource::Misc, goal, None),
233+
);
234+
(result, proof_tree.unwrap())
238235
}
239236
}
240237

compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::ty::{
1414
};
1515
use rustc_next_trait_solver::delegate::SolverDelegate as _;
1616
use rustc_next_trait_solver::solve::{
17-
GenerateProofTree, GoalEvaluation, GoalStalledOn, HasChanged, SolverDelegateEvalExt as _,
17+
GoalEvaluation, GoalStalledOn, HasChanged, SolverDelegateEvalExt as _,
1818
};
1919
use rustc_span::Span;
2020
use thin_vec::ThinVec;
@@ -106,14 +106,11 @@ impl<'tcx> ObligationStorage<'tcx> {
106106
self.overflowed.extend(
107107
ExtractIf::new(&mut self.pending, |(o, stalled_on)| {
108108
let goal = o.as_goal();
109-
let result = <&SolverDelegate<'tcx>>::from(infcx)
110-
.evaluate_root_goal(
111-
goal,
112-
GenerateProofTree::No,
113-
o.cause.span,
114-
stalled_on.take(),
115-
)
116-
.0;
109+
let result = <&SolverDelegate<'tcx>>::from(infcx).evaluate_root_goal(
110+
goal,
111+
o.cause.span,
112+
stalled_on.take(),
113+
);
117114
matches!(result, Ok(GoalEvaluation { has_changed: HasChanged::Yes, .. }))
118115
})
119116
.map(|(o, _)| o),
@@ -207,14 +204,7 @@ where
207204
continue;
208205
}
209206

210-
let result = delegate
211-
.evaluate_root_goal(
212-
goal,
213-
GenerateProofTree::No,
214-
obligation.cause.span,
215-
stalled_on,
216-
)
217-
.0;
207+
let result = delegate.evaluate_root_goal(goal, obligation.cause.span, stalled_on);
218208
self.inspect_evaluated_obligation(infcx, &obligation, &result);
219209
let GoalEvaluation { certainty, has_changed, stalled_on } = match result {
220210
Ok(result) => result,

compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ use rustc_middle::traits::query::NoSolution;
1111
use rustc_middle::ty::error::{ExpectedFound, TypeError};
1212
use rustc_middle::ty::{self, Ty, TyCtxt};
1313
use rustc_middle::{bug, span_bug};
14-
use rustc_next_trait_solver::solve::{
15-
GenerateProofTree, GoalEvaluation, SolverDelegateEvalExt as _,
16-
};
14+
use rustc_next_trait_solver::solve::{GoalEvaluation, SolverDelegateEvalExt as _};
1715
use tracing::{instrument, trace};
1816

1917
use crate::solve::delegate::SolverDelegate;
@@ -90,15 +88,11 @@ pub(super) fn fulfillment_error_for_stalled<'tcx>(
9088
root_obligation: PredicateObligation<'tcx>,
9189
) -> FulfillmentError<'tcx> {
9290
let (code, refine_obligation) = infcx.probe(|_| {
93-
match <&SolverDelegate<'tcx>>::from(infcx)
94-
.evaluate_root_goal(
95-
root_obligation.as_goal(),
96-
GenerateProofTree::No,
97-
root_obligation.cause.span,
98-
None,
99-
)
100-
.0
101-
{
91+
match <&SolverDelegate<'tcx>>::from(infcx).evaluate_root_goal(
92+
root_obligation.as_goal(),
93+
root_obligation.cause.span,
94+
None,
95+
) {
10296
Ok(GoalEvaluation { certainty: Certainty::Maybe(MaybeCause::Ambiguity), .. }) => {
10397
(FulfillmentErrorCode::Ambiguity { overflow: None }, true)
10498
}

compiler/rustc_trait_selection/src/solve/inspect/analyse.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::{TyCtxt, VisitorResult, try_visit};
2020
use rustc_middle::{bug, ty};
2121
use rustc_next_trait_solver::resolve::eager_resolve_vars;
2222
use rustc_next_trait_solver::solve::inspect::{self, instantiate_canonical_state};
23-
use rustc_next_trait_solver::solve::{GenerateProofTree, MaybeCause, SolverDelegateEvalExt as _};
23+
use rustc_next_trait_solver::solve::{MaybeCause, SolverDelegateEvalExt as _};
2424
use rustc_span::Span;
2525
use tracing::instrument;
2626

@@ -248,9 +248,7 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
248248
// considering the constrained RHS, and pass the resulting certainty to
249249
// `InspectGoal::new` so that the goal has the right result (and maintains
250250
// the impression that we don't do this normalizes-to infer hack at all).
251-
let (nested, proof_tree) =
252-
infcx.evaluate_root_goal_raw(goal, GenerateProofTree::Yes, None);
253-
let proof_tree = proof_tree.unwrap();
251+
let (nested, proof_tree) = infcx.evaluate_root_goal_for_proof_tree(goal, span);
254252
let nested_goals_result = nested.and_then(|(nested, _)| {
255253
normalizes_to_term_hack.constrain_and(
256254
infcx,
@@ -284,9 +282,8 @@ impl<'a, 'tcx> InspectCandidate<'a, 'tcx> {
284282
// into another candidate who ends up with different inference
285283
// constraints, we get an ICE if we already applied the constraints
286284
// from the chosen candidate.
287-
let proof_tree = infcx
288-
.probe(|_| infcx.evaluate_root_goal(goal, GenerateProofTree::Yes, span, None).1)
289-
.unwrap();
285+
let proof_tree =
286+
infcx.probe(|_| infcx.evaluate_root_goal_for_proof_tree(goal, span).1);
290287
InspectGoal::new(infcx, self.goal.depth + 1, proof_tree, None, source)
291288
}
292289
}
@@ -488,13 +485,8 @@ impl<'tcx> InferCtxt<'tcx> {
488485
depth: usize,
489486
visitor: &mut V,
490487
) -> V::Result {
491-
let (_, proof_tree) = <&SolverDelegate<'tcx>>::from(self).evaluate_root_goal(
492-
goal,
493-
GenerateProofTree::Yes,
494-
visitor.span(),
495-
None,
496-
);
497-
let proof_tree = proof_tree.unwrap();
488+
let (_, proof_tree) = <&SolverDelegate<'tcx>>::from(self)
489+
.evaluate_root_goal_for_proof_tree(goal, visitor.span());
498490
visitor.visit_goal(&InspectGoal::new(self, depth, proof_tree, None, GoalSource::Misc))
499491
}
500492
}

0 commit comments

Comments
 (0)