aboutsummaryrefslogtreecommitdiff
path: root/crates/salsa
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-13 20:58:36 +0100
committerAleksey Kladov <[email protected]>2018-09-15 22:00:05 +0100
commit8c737255ff876fc61f8dc8a7d33252476a4b4c8d (patch)
tree1adc74bb54f59c6d868a337cc440ed227e43a44b /crates/salsa
parent60fdfec32759d5e006eae9fe09a87b1a28b19983 (diff)
use salsa for new module map
Diffstat (limited to 'crates/salsa')
-rw-r--r--crates/salsa/src/lib.rs20
-rw-r--r--crates/salsa/tests/integration.rs16
2 files changed, 16 insertions, 20 deletions
diff --git a/crates/salsa/src/lib.rs b/crates/salsa/src/lib.rs
index 5de3c7774..75815e8bd 100644
--- a/crates/salsa/src/lib.rs
+++ b/crates/salsa/src/lib.rs
@@ -8,8 +8,8 @@ use std::{
8}; 8};
9use parking_lot::Mutex; 9use parking_lot::Mutex;
10 10
11type GroundQueryFn<T, D> = fn(&T, &D) -> (D, OutputFingerprint); 11type GroundQueryFn<T, D> = Box<Fn(&T, &D) -> (D, OutputFingerprint) + Send + Sync + 'static>;
12type QueryFn<T, D> = fn(&QueryCtx<T, D>, &D) -> (D, OutputFingerprint); 12type QueryFn<T, D> = Box<Fn(&QueryCtx<T, D>, &D) -> (D, OutputFingerprint) + Send + Sync + 'static>;
13 13
14#[derive(Debug)] 14#[derive(Debug)]
15pub struct Db<T, D> { 15pub struct Db<T, D> {
@@ -119,7 +119,7 @@ where
119 res 119 res
120 } 120 }
121 121
122 pub fn get_inner( 122 fn get_inner(
123 &self, 123 &self,
124 query_id: QueryId, 124 query_id: QueryId,
125 params: D, 125 params: D,
@@ -176,9 +176,9 @@ where
176 self.executed.borrow_mut().push(query_id.0); 176 self.executed.borrow_mut().push(query_id.0);
177 self.stack.borrow_mut().push(Vec::new()); 177 self.stack.borrow_mut().push(Vec::new());
178 178
179 let (res, output_fingerprint) = if let Some(f) = self.ground_query_fn_by_type(query_id.0) { 179 let (res, output_fingerprint) = if let Some(f) = self.query_config.ground_fn.get(&query_id.0) {
180 f(&self.db.ground_data, &params) 180 f(&self.db.ground_data, &params)
181 } else if let Some(f) = self.query_fn_by_type(query_id.0) { 181 } else if let Some(f) = self.query_config.query_fn.get(&query_id.0) {
182 f(self, &params) 182 f(self, &params)
183 } else { 183 } else {
184 panic!("unknown query type: {:?}", query_id.0); 184 panic!("unknown query type: {:?}", query_id.0);
@@ -190,12 +190,6 @@ where
190 self.db.record(query_id, params, res.clone(), output_fingerprint, deps); 190 self.db.record(query_id, params, res.clone(), output_fingerprint, deps);
191 (res, output_fingerprint) 191 (res, output_fingerprint)
192 } 192 }
193 fn ground_query_fn_by_type(&self, query_type: QueryTypeId) -> Option<GroundQueryFn<T, D>> {
194 self.query_config.ground_fn.get(&query_type).map(|&it| it)
195 }
196 fn query_fn_by_type(&self, query_type: QueryTypeId) -> Option<QueryFn<T, D>> {
197 self.query_config.query_fn.get(&query_type).map(|&it| it)
198 }
199 fn record_dep( 193 fn record_dep(
200 &self, 194 &self,
201 query_id: QueryId, 195 query_id: QueryId,
@@ -239,7 +233,9 @@ where
239 query_config: Arc::new(query_config), 233 query_config: Arc::new(query_config),
240 } 234 }
241 } 235 }
242 236 pub fn ground_data(&self) -> &T {
237 &self.db.ground_data
238 }
243 pub fn with_ground_data( 239 pub fn with_ground_data(
244 &self, 240 &self,
245 ground_data: T, 241 ground_data: T,
diff --git a/crates/salsa/tests/integration.rs b/crates/salsa/tests/integration.rs
index 3cec330e6..aed9219be 100644
--- a/crates/salsa/tests/integration.rs
+++ b/crates/salsa/tests/integration.rs
@@ -79,19 +79,19 @@ where
79 79
80fn mk_queries() -> salsa::QueryConfig<State, Data> { 80fn mk_queries() -> salsa::QueryConfig<State, Data> {
81 salsa::QueryConfig::<State, Data>::new() 81 salsa::QueryConfig::<State, Data>::new()
82 .with_ground_query(GET_TEXT, |state, id| { 82 .with_ground_query(GET_TEXT, Box::new(|state, id| {
83 mk_ground_query::<u32, String>(state, id, |state, id| state[id].clone()) 83 mk_ground_query::<u32, String>(state, id, |state, id| state[id].clone())
84 }) 84 }))
85 .with_ground_query(GET_FILES, |state, id| { 85 .with_ground_query(GET_FILES, Box::new(|state, id| {
86 mk_ground_query::<(), Vec<u32>>(state, id, |state, &()| state.keys().cloned().collect()) 86 mk_ground_query::<(), Vec<u32>>(state, id, |state, &()| state.keys().cloned().collect())
87 }) 87 }))
88 .with_query(FILE_NEWLINES, |query_ctx, id| { 88 .with_query(FILE_NEWLINES, Box::new(|query_ctx, id| {
89 mk_query(query_ctx, id, |query_ctx, &id| { 89 mk_query(query_ctx, id, |query_ctx, &id| {
90 let text = query_ctx.get_text(id); 90 let text = query_ctx.get_text(id);
91 text.lines().count() 91 text.lines().count()
92 }) 92 })
93 }) 93 }))
94 .with_query(TOTAL_NEWLINES, |query_ctx, id| { 94 .with_query(TOTAL_NEWLINES, Box::new(|query_ctx, id| {
95 mk_query(query_ctx, id, |query_ctx, &()| { 95 mk_query(query_ctx, id, |query_ctx, &()| {
96 let mut total = 0; 96 let mut total = 0;
97 for &id in query_ctx.get_files().iter() { 97 for &id in query_ctx.get_files().iter() {
@@ -99,7 +99,7 @@ fn mk_queries() -> salsa::QueryConfig<State, Data> {
99 } 99 }
100 total 100 total
101 }) 101 })
102 }) 102 }))
103} 103}
104 104
105#[test] 105#[test]