diff options
author | Aleksey Kladov <[email protected]> | 2018-09-13 20:58:36 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-15 22:00:05 +0100 |
commit | 8c737255ff876fc61f8dc8a7d33252476a4b4c8d (patch) | |
tree | 1adc74bb54f59c6d868a337cc440ed227e43a44b /crates/salsa/src/lib.rs | |
parent | 60fdfec32759d5e006eae9fe09a87b1a28b19983 (diff) |
use salsa for new module map
Diffstat (limited to 'crates/salsa/src/lib.rs')
-rw-r--r-- | crates/salsa/src/lib.rs | 20 |
1 files changed, 8 insertions, 12 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 | }; |
9 | use parking_lot::Mutex; | 9 | use parking_lot::Mutex; |
10 | 10 | ||
11 | type GroundQueryFn<T, D> = fn(&T, &D) -> (D, OutputFingerprint); | 11 | type GroundQueryFn<T, D> = Box<Fn(&T, &D) -> (D, OutputFingerprint) + Send + Sync + 'static>; |
12 | type QueryFn<T, D> = fn(&QueryCtx<T, D>, &D) -> (D, OutputFingerprint); | 12 | type QueryFn<T, D> = Box<Fn(&QueryCtx<T, D>, &D) -> (D, OutputFingerprint) + Send + Sync + 'static>; |
13 | 13 | ||
14 | #[derive(Debug)] | 14 | #[derive(Debug)] |
15 | pub struct Db<T, D> { | 15 | pub 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, ¶ms) | 180 | f(&self.db.ground_data, ¶ms) |
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, ¶ms) | 182 | f(self, ¶ms) |
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, |