From cecc7ad5b20e693cb8d962187bd83b9ac234de97 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 12 Sep 2018 22:11:26 +0300 Subject: be generic over data --- crates/salsa/tests/integration.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'crates/salsa/tests/integration.rs') diff --git a/crates/salsa/tests/integration.rs b/crates/salsa/tests/integration.rs index 7241eca38..2872d3913 100644 --- a/crates/salsa/tests/integration.rs +++ b/crates/salsa/tests/integration.rs @@ -7,6 +7,7 @@ use std::{ }; type State = HashMap; +type Data = Arc; const GET_TEXT: salsa::QueryTypeId = salsa::QueryTypeId(1); const GET_FILES: salsa::QueryTypeId = salsa::QueryTypeId(2); const FILE_NEWLINES: salsa::QueryTypeId = salsa::QueryTypeId(3); @@ -14,9 +15,9 @@ const TOTAL_NEWLINES: salsa::QueryTypeId = salsa::QueryTypeId(4); fn mk_ground_query( state: &State, - params: &(Any + Send + Sync + 'static), + params: &Data, f: fn(&State, &T) -> R, -) -> (Box, salsa::OutputFingerprint) +) -> (Data, salsa::OutputFingerprint) where T: 'static, R: Hash + Send + Sync + 'static, @@ -24,21 +25,21 @@ where let params = params.downcast_ref().unwrap(); let result = f(state, params); let fingerprint = o_print(&result); - (Box::new(result), fingerprint) + (Arc::new(result), fingerprint) } -fn get(db: &salsa::Db, query_type: salsa::QueryTypeId, param: T) -> (Arc, Vec) +fn get(db: &salsa::Db, query_type: salsa::QueryTypeId, param: T) -> (Arc, Vec) where T: Hash + Send + Sync + 'static, R: Send + Sync + 'static, { let i_print = i_print(¶m); - let param = Box::new(param); + let param = Arc::new(param); let (res, trace) = db.get(salsa::QueryId(query_type, i_print), param); (res.downcast().unwrap(), trace) } -struct QueryCtx<'a>(&'a salsa::QueryCtx); +struct QueryCtx<'a>(&'a salsa::QueryCtx); impl<'a> QueryCtx<'a> { fn get_text(&self, id: u32) -> Arc { @@ -60,10 +61,10 @@ impl<'a> QueryCtx<'a> { } fn mk_query( - query_ctx: &salsa::QueryCtx, - params: &(Any + Send + Sync + 'static), + query_ctx: &salsa::QueryCtx, + params: &Data, f: fn(QueryCtx, &T) -> R, -) -> (Box, salsa::OutputFingerprint) +) -> (Data, salsa::OutputFingerprint) where T: 'static, R: Hash + Send + Sync + 'static, @@ -72,11 +73,11 @@ where let query_ctx = QueryCtx(query_ctx); let result = f(query_ctx, params); let fingerprint = o_print(&result); - (Box::new(result), fingerprint) + (Arc::new(result), fingerprint) } -fn mk_queries() -> salsa::QueryConfig { - salsa::QueryConfig::::new() +fn mk_queries() -> salsa::QueryConfig { + salsa::QueryConfig::::new() .with_ground_query(GET_TEXT, |state, id| { mk_ground_query::(state, id, |state, id| state[id].clone()) }) -- cgit v1.2.3