Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c3ebb53

Browse files
committedFeb 11, 2025·
change proven_via probe to be coinductive
1 parent 8f2920b commit c3ebb53

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed
 

Diff for: ‎compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ where
6060
/// when then adds these to its own context. The caller is always an `AliasRelate`
6161
/// goal so this never leaks out of the solver.
6262
is_normalizes_to_goal: bool,
63+
64+
/// Whether the current `probe` should be treated as a coinductive step when encountering
65+
/// trait solver cycles. This changes the step kind of all nested goals computed in that
66+
/// probe to be coinductive.
67+
is_coinductive_probe: bool,
68+
6369
pub(super) var_values: CanonicalVarValues<I>,
6470

6571
predefined_opaques_in_body: I::PredefinedOpaques,
@@ -232,6 +238,10 @@ where
232238
}
233239

234240
pub(super) fn step_kind_for_source(&self, source: GoalSource) -> PathKind {
241+
if self.is_coinductive_probe {
242+
return PathKind::Coinductive;
243+
}
244+
235245
match source {
236246
GoalSource::ImplWhereBound => PathKind::Coinductive,
237247
_ => PathKind::Inductive,
@@ -265,6 +275,7 @@ where
265275
variables: Default::default(),
266276
var_values: CanonicalVarValues::dummy(),
267277
is_normalizes_to_goal: false,
278+
is_coinductive_probe: false,
268279
origin_span,
269280
tainted: Ok(()),
270281
};
@@ -303,6 +314,7 @@ where
303314
variables: canonical_input.canonical.variables,
304315
var_values,
305316
is_normalizes_to_goal: false,
317+
is_coinductive_probe: false,
306318
predefined_opaques_in_body: input.predefined_opaques_in_body,
307319
max_input_universe: canonical_input.canonical.max_universe,
308320
search_graph,

Diff for: ‎compiler/rustc_next_trait_solver/src/solve/eval_ctxt/probe.rs

+36
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,42 @@ where
3535
variables: outer_ecx.variables,
3636
var_values: outer_ecx.var_values,
3737
is_normalizes_to_goal: outer_ecx.is_normalizes_to_goal,
38+
is_coinductive_probe: outer_ecx.is_coinductive_probe,
39+
predefined_opaques_in_body: outer_ecx.predefined_opaques_in_body,
40+
max_input_universe,
41+
search_graph: outer_ecx.search_graph,
42+
nested_goals: outer_ecx.nested_goals.clone(),
43+
origin_span: outer_ecx.origin_span,
44+
tainted: outer_ecx.tainted,
45+
inspect: outer_ecx.inspect.take_and_enter_probe(),
46+
};
47+
let r = nested_ecx.delegate.probe(|| {
48+
let r = f(&mut nested_ecx);
49+
nested_ecx.inspect.probe_final_state(delegate, max_input_universe);
50+
r
51+
});
52+
if !nested_ecx.inspect.is_noop() {
53+
let probe_kind = probe_kind(&r);
54+
nested_ecx.inspect.probe_kind(probe_kind);
55+
outer_ecx.inspect = nested_ecx.inspect.finish_probe();
56+
}
57+
r
58+
}
59+
60+
pub(in crate::solve) fn enter_coinductively(
61+
self,
62+
f: impl FnOnce(&mut EvalCtxt<'_, D>) -> T,
63+
) -> T {
64+
let ProbeCtxt { ecx: outer_ecx, probe_kind, _result } = self;
65+
66+
let delegate = outer_ecx.delegate;
67+
let max_input_universe = outer_ecx.max_input_universe;
68+
let mut nested_ecx = EvalCtxt {
69+
delegate,
70+
variables: outer_ecx.variables,
71+
var_values: outer_ecx.var_values,
72+
is_normalizes_to_goal: outer_ecx.is_normalizes_to_goal,
73+
is_coinductive_probe: true,
3874
predefined_opaques_in_body: outer_ecx.predefined_opaques_in_body,
3975
max_input_universe,
4076
search_graph: outer_ecx.search_graph,

Diff for: ‎compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ where
9393
ty::AliasTermKind::ProjectionTy | ty::AliasTermKind::ProjectionConst => {
9494
let candidates = self.assemble_and_evaluate_candidates(goal);
9595
let (_, proven_via) =
96-
self.probe(|_| ProbeKind::ShadowedEnvProbing).enter(|ecx| {
96+
self.probe(|_| ProbeKind::ShadowedEnvProbing).enter_coinductively(|ecx| {
9797
let trait_goal: Goal<I, ty::TraitPredicate<I>> =
9898
goal.with(cx, goal.predicate.alias.trait_ref(cx));
9999
ecx.compute_trait_goal(trait_goal)

0 commit comments

Comments
 (0)
Please sign in to comment.