1- use crate :: solve:: slg:: SlgContext ;
2- use crate :: { recursive:: RecursiveContext , RustIrDatabase } ;
3- use chalk_engine:: forest:: { Forest , SubstitutionResult } ;
1+ use crate :: RustIrDatabase ;
42use chalk_ir:: interner:: Interner ;
53use chalk_ir:: * ;
64use std:: fmt;
75
6+ #[ cfg( feature = "slg-solver" ) ]
7+ use {
8+ crate :: solve:: slg:: SlgContext ,
9+ chalk_engine:: forest:: { Forest , SubstitutionResult } ,
10+ } ;
11+
12+ #[ cfg( feature = "recursive-solver" ) ]
13+ use crate :: recursive:: RecursiveContext ;
14+
15+ #[ cfg( feature = "slg-solver" ) ]
816mod slg;
917pub ( crate ) mod truncate;
1018
@@ -179,11 +187,13 @@ impl<'a, I: Interner> fmt::Display for SolutionDisplay<'a, I> {
179187#[ derive( Copy , Clone , Debug , PartialOrd , Ord , PartialEq , Eq , Hash ) ]
180188pub enum SolverChoice {
181189 /// Run the SLG solver, producing a Solution.
190+ #[ cfg( feature = "slg-solver" ) ]
182191 SLG {
183192 max_size : usize ,
184193 expected_answers : Option < usize > ,
185194 } ,
186195 /// Run the recursive solver.
196+ #[ cfg( feature = "recursive-solver" ) ]
187197 Recursive {
188198 overflow_depth : usize ,
189199 caching_enabled : bool ,
@@ -192,6 +202,7 @@ pub enum SolverChoice {
192202
193203impl SolverChoice {
194204 /// Returns specific SLG parameters.
205+ #[ cfg( feature = "slg-solver" ) ]
195206 pub fn slg ( max_size : usize , expected_answers : Option < usize > ) -> Self {
196207 SolverChoice :: SLG {
197208 max_size,
@@ -200,11 +211,13 @@ impl SolverChoice {
200211 }
201212
202213 /// Returns the default SLG parameters.
214+ #[ cfg( feature = "slg-solver" ) ]
203215 pub fn slg_default ( ) -> Self {
204216 SolverChoice :: slg ( 10 , None )
205217 }
206218
207219 /// Returns the default recursive solver setup.
220+ #[ cfg( feature = "recursive-solver" ) ]
208221 pub fn recursive ( ) -> Self {
209222 SolverChoice :: Recursive {
210223 overflow_depth : 100 ,
@@ -215,12 +228,14 @@ impl SolverChoice {
215228 /// Creates a solver state.
216229 pub fn into_solver < I : Interner > ( self ) -> Solver < I > {
217230 match self {
231+ #[ cfg( feature = "slg-solver" ) ]
218232 SolverChoice :: SLG {
219233 max_size,
220234 expected_answers,
221235 } => Solver ( SolverImpl :: Slg {
222236 forest : Box :: new ( Forest :: new ( SlgContext :: new ( max_size, expected_answers) ) ) ,
223237 } ) ,
238+ #[ cfg( feature = "recursive-solver" ) ]
224239 SolverChoice :: Recursive {
225240 overflow_depth,
226241 caching_enabled,
@@ -232,10 +247,17 @@ impl SolverChoice {
232247 }
233248}
234249
250+ #[ cfg( feature = "slg-solver" ) ]
235251impl Default for SolverChoice {
236252 fn default ( ) -> Self {
237- // SolverChoice::recursive()
238- SolverChoice :: slg ( 10 , None )
253+ SolverChoice :: slg_default ( )
254+ }
255+ }
256+
257+ #[ cfg( all( not( feature = "slg-solver" ) , feature = "recursive-solver" ) ) ]
258+ impl Default for SolverChoice {
259+ fn default ( ) -> Self {
260+ SolverChoice :: recursive ( )
239261 }
240262}
241263
@@ -246,7 +268,9 @@ impl Default for SolverChoice {
246268pub struct Solver < I : Interner > ( SolverImpl < I > ) ;
247269
248270enum SolverImpl < I : Interner > {
271+ #[ cfg( feature = "slg-solver" ) ]
249272 Slg { forest : Box < Forest < SlgContext < I > > > } ,
273+ #[ cfg( feature = "recursive-solver" ) ]
250274 Recursive ( Box < RecursiveContext < I > > ) ,
251275}
252276
@@ -275,10 +299,12 @@ impl<I: Interner> Solver<I> {
275299 goal : & UCanonical < InEnvironment < Goal < I > > > ,
276300 ) -> Option < Solution < I > > {
277301 match & mut self . 0 {
302+ #[ cfg( feature = "slg-solver" ) ]
278303 SolverImpl :: Slg { forest } => {
279304 let ops = forest. context ( ) . ops ( program) ;
280305 forest. solve ( & ops, goal, || true )
281306 }
307+ #[ cfg( feature = "recursive-solver" ) ]
282308 SolverImpl :: Recursive ( ctx) => ctx. solver ( program) . solve_root_goal ( goal) . ok ( ) ,
283309 }
284310 }
@@ -312,10 +338,12 @@ impl<I: Interner> Solver<I> {
312338 should_continue : impl std:: ops:: Fn ( ) -> bool ,
313339 ) -> Option < Solution < I > > {
314340 match & mut self . 0 {
341+ #[ cfg( feature = "slg-solver" ) ]
315342 SolverImpl :: Slg { forest } => {
316343 let ops = forest. context ( ) . ops ( program) ;
317344 forest. solve ( & ops, goal, should_continue)
318345 }
346+ #[ cfg( feature = "recursive-solver" ) ]
319347 SolverImpl :: Recursive ( ctx) => {
320348 // TODO support should_continue in recursive solver
321349 ctx. solver ( program) . solve_root_goal ( goal) . ok ( )
@@ -345,6 +373,7 @@ impl<I: Interner> Solver<I> {
345373 ///
346374 /// - `true` all solutions were processed with the function.
347375 /// - `false` the function returned `false` and solutions were interrupted.
376+ #[ cfg( feature = "slg-solver" ) ]
348377 pub fn solve_multiple (
349378 & mut self ,
350379 program : & dyn RustIrDatabase < I > ,
@@ -356,6 +385,7 @@ impl<I: Interner> Solver<I> {
356385 let ops = forest. context ( ) . ops ( program) ;
357386 forest. solve_multiple ( & ops, goal, f)
358387 }
388+ #[ cfg( feature = "recursive-solver" ) ]
359389 SolverImpl :: Recursive ( _ctx) => unimplemented ! ( ) ,
360390 }
361391 }
0 commit comments