diff options
-rw-r--r-- | crates/ra_hir/src/db.rs | 7 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/traits.rs | 6 |
2 files changed, 10 insertions, 3 deletions
diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index b2c4fccf2..8aaf0375a 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs | |||
@@ -153,9 +153,14 @@ pub trait HirDatabase: DefDatabase { | |||
153 | #[salsa::invoke(crate::ty::traits::impls_for_trait)] | 153 | #[salsa::invoke(crate::ty::traits::impls_for_trait)] |
154 | fn impls_for_trait(&self, krate: Crate, trait_: Trait) -> Arc<[ImplBlock]>; | 154 | fn impls_for_trait(&self, krate: Crate, trait_: Trait) -> Arc<[ImplBlock]>; |
155 | 155 | ||
156 | /// This provides the Chalk trait solver instance. Because Chalk always | ||
157 | /// works from a specific crate, this query is keyed on the crate; and | ||
158 | /// because Chalk does its own internal caching, the solver is wrapped in a | ||
159 | /// Mutex and the query is marked volatile, to make sure the cached state is | ||
160 | /// thrown away when input facts change. | ||
156 | #[salsa::invoke(crate::ty::traits::solver)] | 161 | #[salsa::invoke(crate::ty::traits::solver)] |
157 | #[salsa::volatile] | 162 | #[salsa::volatile] |
158 | fn chalk_solver(&self, krate: Crate) -> Arc<Mutex<chalk_solve::Solver>>; | 163 | fn solver(&self, krate: Crate) -> Arc<Mutex<crate::ty::traits::Solver>>; |
159 | } | 164 | } |
160 | 165 | ||
161 | #[test] | 166 | #[test] |
diff --git a/crates/ra_hir/src/ty/traits.rs b/crates/ra_hir/src/ty/traits.rs index acb69683c..ac31ca2f6 100644 --- a/crates/ra_hir/src/ty/traits.rs +++ b/crates/ra_hir/src/ty/traits.rs | |||
@@ -10,13 +10,15 @@ use self::chalk::{ToChalk, from_chalk}; | |||
10 | 10 | ||
11 | mod chalk; | 11 | mod chalk; |
12 | 12 | ||
13 | pub(crate) type Solver = chalk_solve::Solver; | ||
14 | |||
13 | #[derive(Debug, Copy, Clone)] | 15 | #[derive(Debug, Copy, Clone)] |
14 | struct ChalkContext<'a, DB> { | 16 | struct ChalkContext<'a, DB> { |
15 | db: &'a DB, | 17 | db: &'a DB, |
16 | krate: Crate, | 18 | krate: Crate, |
17 | } | 19 | } |
18 | 20 | ||
19 | pub(crate) fn solver(_db: &impl HirDatabase, _krate: Crate) -> Arc<Mutex<chalk_solve::Solver>> { | 21 | pub(crate) fn solver(_db: &impl HirDatabase, _krate: Crate) -> Arc<Mutex<Solver>> { |
20 | // krate parameter is just so we cache a unique solver per crate | 22 | // krate parameter is just so we cache a unique solver per crate |
21 | let solver_choice = chalk_solve::SolverChoice::SLG { max_size: 10 }; | 23 | let solver_choice = chalk_solve::SolverChoice::SLG { max_size: 10 }; |
22 | Arc::new(Mutex::new(solver_choice.into_solver())) | 24 | Arc::new(Mutex::new(solver_choice.into_solver())) |
@@ -48,7 +50,7 @@ fn solve( | |||
48 | goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal>>, | 50 | goal: &chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal>>, |
49 | ) -> Option<chalk_solve::Solution> { | 51 | ) -> Option<chalk_solve::Solution> { |
50 | let context = ChalkContext { db, krate }; | 52 | let context = ChalkContext { db, krate }; |
51 | let solver = db.chalk_solver(krate); | 53 | let solver = db.solver(krate); |
52 | let solution = solver.lock().unwrap().solve(&context, goal); | 54 | let solution = solver.lock().unwrap().solve(&context, goal); |
53 | eprintln!("solve({:?}) => {:?}", goal, solution); | 55 | eprintln!("solve({:?}) => {:?}", goal, solution); |
54 | solution | 56 | solution |