From 8c737255ff876fc61f8dc8a7d33252476a4b4c8d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 13 Sep 2018 22:58:36 +0300 Subject: use salsa for new module map --- crates/salsa/src/lib.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'crates/salsa/src') 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::{ }; use parking_lot::Mutex; -type GroundQueryFn = fn(&T, &D) -> (D, OutputFingerprint); -type QueryFn = fn(&QueryCtx, &D) -> (D, OutputFingerprint); +type GroundQueryFn = Box (D, OutputFingerprint) + Send + Sync + 'static>; +type QueryFn = Box, &D) -> (D, OutputFingerprint) + Send + Sync + 'static>; #[derive(Debug)] pub struct Db { @@ -119,7 +119,7 @@ where res } - pub fn get_inner( + fn get_inner( &self, query_id: QueryId, params: D, @@ -176,9 +176,9 @@ where self.executed.borrow_mut().push(query_id.0); self.stack.borrow_mut().push(Vec::new()); - let (res, output_fingerprint) = if let Some(f) = self.ground_query_fn_by_type(query_id.0) { + let (res, output_fingerprint) = if let Some(f) = self.query_config.ground_fn.get(&query_id.0) { f(&self.db.ground_data, ¶ms) - } else if let Some(f) = self.query_fn_by_type(query_id.0) { + } else if let Some(f) = self.query_config.query_fn.get(&query_id.0) { f(self, ¶ms) } else { panic!("unknown query type: {:?}", query_id.0); @@ -190,12 +190,6 @@ where self.db.record(query_id, params, res.clone(), output_fingerprint, deps); (res, output_fingerprint) } - fn ground_query_fn_by_type(&self, query_type: QueryTypeId) -> Option> { - self.query_config.ground_fn.get(&query_type).map(|&it| it) - } - fn query_fn_by_type(&self, query_type: QueryTypeId) -> Option> { - self.query_config.query_fn.get(&query_type).map(|&it| it) - } fn record_dep( &self, query_id: QueryId, @@ -239,7 +233,9 @@ where query_config: Arc::new(query_config), } } - + pub fn ground_data(&self) -> &T { + &self.db.ground_data + } pub fn with_ground_data( &self, ground_data: T, -- cgit v1.2.3