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 ++++++++------------ crates/salsa/tests/integration.rs | 16 ++++++++-------- 2 files changed, 16 insertions(+), 20 deletions(-) (limited to 'crates/salsa') 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, 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 fn mk_queries() -> salsa::QueryConfig { salsa::QueryConfig::::new() - .with_ground_query(GET_TEXT, |state, id| { + .with_ground_query(GET_TEXT, Box::new(|state, id| { mk_ground_query::(state, id, |state, id| state[id].clone()) - }) - .with_ground_query(GET_FILES, |state, id| { + })) + .with_ground_query(GET_FILES, Box::new(|state, id| { mk_ground_query::<(), Vec>(state, id, |state, &()| state.keys().cloned().collect()) - }) - .with_query(FILE_NEWLINES, |query_ctx, id| { + })) + .with_query(FILE_NEWLINES, Box::new(|query_ctx, id| { mk_query(query_ctx, id, |query_ctx, &id| { let text = query_ctx.get_text(id); text.lines().count() }) - }) - .with_query(TOTAL_NEWLINES, |query_ctx, id| { + })) + .with_query(TOTAL_NEWLINES, Box::new(|query_ctx, id| { mk_query(query_ctx, id, |query_ctx, &()| { let mut total = 0; for &id in query_ctx.get_files().iter() { @@ -99,7 +99,7 @@ fn mk_queries() -> salsa::QueryConfig { } total }) - }) + })) } #[test] -- cgit v1.2.3