Skip to content

Commit 9cbd071

Browse files
committed
move solve-root-goal
1 parent d736b5c commit 9cbd071

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

chalk-recursive/src/recursive.rs

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ where
8080
}
8181
}
8282

83+
/// Solves a canonical goal. The substitution returned in the
84+
/// solution will be for the fully decomposed goal. For example, given the
85+
/// program
86+
///
87+
/// ```ignore
88+
/// struct u8 { }
89+
/// struct SomeType<T> { }
90+
/// trait Foo<T> { }
91+
/// impl<U> Foo<u8> for SomeType<U> { }
92+
/// ```
93+
///
94+
/// and the goal `exists<V> { forall<U> { SomeType<U>: Foo<V> }
95+
/// }`, `into_peeled_goal` can be used to create a canonical goal
96+
/// `SomeType<!1>: Foo<?0>`. This function will then return a
97+
/// solution with the substitution `?0 := u8`.
98+
pub(crate) fn solve_root_goal(
99+
&mut self,
100+
canonical_goal: &K,
101+
solver_stuff: impl SolverStuff<K, V>,
102+
) -> V {
103+
debug!("solve_root_goal(canonical_goal={:?})", canonical_goal);
104+
assert!(self.stack.is_empty());
105+
let minimums = &mut Minimums::new();
106+
self.solve_goal(canonical_goal, minimums, solver_stuff)
107+
}
108+
83109
/// Attempt to solve a goal that has been fully broken down into leaf form
84110
/// and canonicalized. This is where the action really happens, and is the
85111
/// place where we would perform caching in rustc (and may eventually do in Chalk).
@@ -212,31 +238,6 @@ impl<'me, I: Interner> Solver<'me, I> {
212238
) -> Self {
213239
Self { program, context }
214240
}
215-
216-
/// Solves a canonical goal. The substitution returned in the
217-
/// solution will be for the fully decomposed goal. For example, given the
218-
/// program
219-
///
220-
/// ```ignore
221-
/// struct u8 { }
222-
/// struct SomeType<T> { }
223-
/// trait Foo<T> { }
224-
/// impl<U> Foo<u8> for SomeType<U> { }
225-
/// ```
226-
///
227-
/// and the goal `exists<V> { forall<U> { SomeType<U>: Foo<V> }
228-
/// }`, `into_peeled_goal` can be used to create a canonical goal
229-
/// `SomeType<!1>: Foo<?0>`. This function will then return a
230-
/// solution with the substitution `?0 := u8`.
231-
pub(crate) fn solve_root_goal(
232-
&mut self,
233-
canonical_goal: &UCanonicalGoal<I>,
234-
) -> Fallible<Solution<I>> {
235-
debug!("solve_root_goal(canonical_goal={:?})", canonical_goal);
236-
assert!(self.context.stack.is_empty());
237-
let minimums = &mut Minimums::new();
238-
self.solve_goal(canonical_goal.clone(), minimums)
239-
}
240241
}
241242

242243
trait SolverStuff<K, V>: Copy
@@ -339,9 +340,7 @@ impl<I: Interner> chalk_solve::Solver<I> for RecursiveSolver<I> {
339340
program: &dyn RustIrDatabase<I>,
340341
goal: &UCanonical<InEnvironment<Goal<I>>>,
341342
) -> Option<chalk_solve::Solution<I>> {
342-
Solver::new(&mut self.ctx, program)
343-
.solve_root_goal(goal)
344-
.ok()
343+
self.ctx.solve_root_goal(goal, program).ok()
345344
}
346345

347346
fn solve_limited(
@@ -351,9 +350,7 @@ impl<I: Interner> chalk_solve::Solver<I> for RecursiveSolver<I> {
351350
_should_continue: &dyn std::ops::Fn() -> bool,
352351
) -> Option<chalk_solve::Solution<I>> {
353352
// TODO support should_continue in recursive solver
354-
Solver::new(&mut self.ctx, program)
355-
.solve_root_goal(goal)
356-
.ok()
353+
self.ctx.solve_root_goal(goal, program).ok()
357354
}
358355

359356
fn solve_multiple(

0 commit comments

Comments
 (0)