Trait chalk_solve::solve::Solver
source · pub trait Solver<I: Interner>where
Self: Debug,{
// Required methods
fn solve(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
) -> Option<Solution<I>>;
fn solve_limited(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
should_continue: &dyn Fn() -> bool,
) -> Option<Solution<I>>;
fn solve_multiple(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
f: &mut dyn FnMut(SubstitutionResult<Canonical<ConstrainedSubst<I>>>, bool) -> bool,
) -> bool;
// Provided method
fn has_unique_solution(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
) -> bool { ... }
}
Expand description
Finds the solution to “goals”, or trait queries – i.e., figures out what sets of types implement which traits. Also, between queries, this struct stores the cached state from previous solver attempts, which can then be re-used later.
Required Methods§
sourcefn solve(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
) -> Option<Solution<I>>
fn solve( &mut self, program: &dyn RustIrDatabase<I>, goal: &UCanonical<InEnvironment<Goal<I>>>, ) -> Option<Solution<I>>
Attempts to solve the given goal, which must be in canonical
form. Returns a unique solution (if one exists). This will do
only as much work towards goal
as it has to (and that work
is cached for future attempts).
§Parameters
program
– defines the program clauses in scope.- Important: You must supply the same set of program clauses
each time you invoke
solve
, as otherwise the cached data may be invalid.
- Important: You must supply the same set of program clauses
each time you invoke
goal
the goal to solve
§Returns
None
is the goal cannot be proven.Some(solution)
if we succeeded in finding some answers, althoughsolution
may reflect ambiguity and unknowns.
sourcefn solve_limited(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
should_continue: &dyn Fn() -> bool,
) -> Option<Solution<I>>
fn solve_limited( &mut self, program: &dyn RustIrDatabase<I>, goal: &UCanonical<InEnvironment<Goal<I>>>, should_continue: &dyn Fn() -> bool, ) -> Option<Solution<I>>
Attempts to solve the given goal, which must be in canonical
form. Returns a unique solution (if one exists). This will do
only as much work towards goal
as it has to (and that work
is cached for future attempts). In addition, the solving of the
goal can be limited by returning false
from should_continue
.
§Parameters
program
– defines the program clauses in scope.- Important: You must supply the same set of program clauses
each time you invoke
solve
, as otherwise the cached data may be invalid.
- Important: You must supply the same set of program clauses
each time you invoke
goal
the goal to solveshould_continue
iffalse
is returned, the no further solving will be done. AGuidance(Suggested(...))
will be returned aSolution
, using any answers that were generated up to that point.
§Returns
None
is the goal cannot be proven.Some(solution)
if we succeeded in finding some answers, althoughsolution
may reflect ambiguity and unknowns.
sourcefn solve_multiple(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
f: &mut dyn FnMut(SubstitutionResult<Canonical<ConstrainedSubst<I>>>, bool) -> bool,
) -> bool
fn solve_multiple( &mut self, program: &dyn RustIrDatabase<I>, goal: &UCanonical<InEnvironment<Goal<I>>>, f: &mut dyn FnMut(SubstitutionResult<Canonical<ConstrainedSubst<I>>>, bool) -> bool, ) -> bool
Attempts to solve the given goal, which must be in canonical
form. Provides multiple solutions to function f
. This will do
only as much work towards goal
as it has to (and that work
is cached for future attempts).
§Parameters
program
– defines the program clauses in scope.- Important: You must supply the same set of program clauses
each time you invoke
solve
, as otherwise the cached data may be invalid.
- Important: You must supply the same set of program clauses
each time you invoke
goal
the goal to solvef
– function to proceed solution. New solutions will be generated while function returnstrue
.- first argument is solution found
- second argument is the next solution present
- returns true if next solution should be handled
§Returns
true
all solutions were processed with the function.false
the function returnedfalse
and solutions were interrupted.
Provided Methods§
sourcefn has_unique_solution(
&mut self,
program: &dyn RustIrDatabase<I>,
goal: &UCanonical<InEnvironment<Goal<I>>>,
) -> bool
fn has_unique_solution( &mut self, program: &dyn RustIrDatabase<I>, goal: &UCanonical<InEnvironment<Goal<I>>>, ) -> bool
A convenience method for when one doesn’t need the actual solution, only whether or not one exists.