aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2019-05-01 16:13:33 +0100
committerFlorian Diebold <[email protected]>2019-05-04 17:18:30 +0100
commitef77d8375130d12678d4b2316cc1708c90349dad (patch)
tree37f495100cfcb5a8ce9e0bae8ed4fc50e3b49d80 /crates/ra_hir/src
parentc8a643f090ed88289c7bc17b48078e39b932c8a4 (diff)
Document the peculiarity of the solver query a bit
Also remove the only remaining mention of chalk outside of the ty::traits module.
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/db.rs7
-rw-r--r--crates/ra_hir/src/ty/traits.rs6
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
11mod chalk; 11mod chalk;
12 12
13pub(crate) type Solver = chalk_solve::Solver;
14
13#[derive(Debug, Copy, Clone)] 15#[derive(Debug, Copy, Clone)]
14struct ChalkContext<'a, DB> { 16struct ChalkContext<'a, DB> {
15 db: &'a DB, 17 db: &'a DB,
16 krate: Crate, 18 krate: Crate,
17} 19}
18 20
19pub(crate) fn solver(_db: &impl HirDatabase, _krate: Crate) -> Arc<Mutex<chalk_solve::Solver>> { 21pub(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