@@ -50,10 +50,19 @@ impl TraitSolver {
5050 Err ( _) => ra_db:: Canceled :: throw ( ) ,
5151 } ;
5252
53+ let fuel = std:: cell:: Cell :: new ( CHALK_SOLVER_FUEL ) ;
54+
5355 let solution = panic:: catch_unwind ( {
5456 let solver = panic:: AssertUnwindSafe ( & mut solver) ;
5557 let context = panic:: AssertUnwindSafe ( & context) ;
56- move || solver. 0 . solve ( context. 0 , goal)
58+ move || {
59+ solver. 0 . solve_limited ( context. 0 , goal, || {
60+ context. 0 . db . check_canceled ( ) ;
61+ let remaining = fuel. get ( ) ;
62+ fuel. set ( remaining - 1 ) ;
63+ remaining > 0
64+ } )
65+ }
5766 } ) ;
5867
5968 let solution = match solution {
@@ -79,6 +88,9 @@ impl TraitSolver {
7988/// high, we can run into slow edge cases; if we set it too low, Chalk won't
8089/// find some solutions.
8190const CHALK_SOLVER_MAX_SIZE : usize = 4 ;
91+ /// This controls how much 'time' we give the Chalk solver before giving up.
92+ const CHALK_SOLVER_FUEL : i32 = 100 ;
93+ // TODO: tune both these values
8294
8395#[ derive( Debug , Copy , Clone ) ]
8496struct ChalkContext < ' a , DB > {
@@ -97,7 +109,8 @@ pub(crate) fn trait_solver_query(
97109}
98110
99111fn create_chalk_solver ( ) -> chalk_solve:: Solver < TypeFamily > {
100- let solver_choice = chalk_solve:: SolverChoice :: SLG { max_size : CHALK_SOLVER_MAX_SIZE } ;
112+ let solver_choice =
113+ chalk_solve:: SolverChoice :: SLG { max_size : CHALK_SOLVER_MAX_SIZE , expected_answers : None } ;
101114 solver_choice. into_solver ( )
102115}
103116
@@ -232,7 +245,6 @@ fn solution_from_chalk(
232245 let convert_subst = |subst : chalk_ir:: Canonical < chalk_ir:: Substitution < TypeFamily > > | {
233246 let value = subst
234247 . value
235- . parameters
236248 . into_iter ( )
237249 . map ( |p| {
238250 let ty = match p. ty ( ) {
0 commit comments