diff options
Diffstat (limited to 'crates/ra_hir_ty/src/traits.rs')
-rw-r--r-- | crates/ra_hir_ty/src/traits.rs | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 4aabd66dc..88af61e87 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs | |||
@@ -50,10 +50,19 @@ impl TraitSolver { | |||
50 | Err(_) => ra_db::Canceled::throw(), | 50 | Err(_) => ra_db::Canceled::throw(), |
51 | }; | 51 | }; |
52 | 52 | ||
53 | let fuel = std::cell::Cell::new(CHALK_SOLVER_FUEL); | ||
54 | |||
53 | let solution = panic::catch_unwind({ | 55 | let solution = panic::catch_unwind({ |
54 | let solver = panic::AssertUnwindSafe(&mut solver); | 56 | let solver = panic::AssertUnwindSafe(&mut solver); |
55 | let context = panic::AssertUnwindSafe(&context); | 57 | 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 | } | ||
57 | }); | 66 | }); |
58 | 67 | ||
59 | let solution = match solution { | 68 | let solution = match solution { |
@@ -78,7 +87,9 @@ impl TraitSolver { | |||
78 | /// This controls the maximum size of types Chalk considers. If we set this too | 87 | /// This controls the maximum size of types Chalk considers. If we set this too |
79 | /// high, we can run into slow edge cases; if we set it too low, Chalk won't | 88 | /// high, we can run into slow edge cases; if we set it too low, Chalk won't |
80 | /// find some solutions. | 89 | /// find some solutions. |
81 | const CHALK_SOLVER_MAX_SIZE: usize = 4; | 90 | const CHALK_SOLVER_MAX_SIZE: usize = 10; |
91 | /// This controls how much 'time' we give the Chalk solver before giving up. | ||
92 | const CHALK_SOLVER_FUEL: i32 = 100; | ||
82 | 93 | ||
83 | #[derive(Debug, Copy, Clone)] | 94 | #[derive(Debug, Copy, Clone)] |
84 | struct ChalkContext<'a, DB> { | 95 | struct ChalkContext<'a, DB> { |
@@ -97,7 +108,8 @@ pub(crate) fn trait_solver_query( | |||
97 | } | 108 | } |
98 | 109 | ||
99 | fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> { | 110 | fn create_chalk_solver() -> chalk_solve::Solver<TypeFamily> { |
100 | let solver_choice = chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE }; | 111 | let solver_choice = |
112 | chalk_solve::SolverChoice::SLG { max_size: CHALK_SOLVER_MAX_SIZE, expected_answers: None }; | ||
101 | solver_choice.into_solver() | 113 | solver_choice.into_solver() |
102 | } | 114 | } |
103 | 115 | ||
@@ -232,7 +244,6 @@ fn solution_from_chalk( | |||
232 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| { | 244 | let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<TypeFamily>>| { |
233 | let value = subst | 245 | let value = subst |
234 | .value | 246 | .value |
235 | .parameters | ||
236 | .into_iter() | 247 | .into_iter() |
237 | .map(|p| { | 248 | .map(|p| { |
238 | let ty = match p.ty() { | 249 | let ty = match p.ty() { |