aboutsummaryrefslogtreecommitdiff
path: root/crates/salsa/tests/integration.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-09-12 20:11:26 +0100
committerAleksey Kladov <[email protected]>2018-09-15 22:00:05 +0100
commitcecc7ad5b20e693cb8d962187bd83b9ac234de97 (patch)
tree4bb388adae050ba0457cb0ca3b2bfcc9af353871 /crates/salsa/tests/integration.rs
parent8cf9c2719652d298006d51bc82a32908ab4e5335 (diff)
be generic over data
Diffstat (limited to 'crates/salsa/tests/integration.rs')
-rw-r--r--crates/salsa/tests/integration.rs25
1 files changed, 13 insertions, 12 deletions
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::{
7}; 7};
8 8
9type State = HashMap<u32, String>; 9type State = HashMap<u32, String>;
10type Data = Arc<Any + Send + Sync + 'static>;
10const GET_TEXT: salsa::QueryTypeId = salsa::QueryTypeId(1); 11const GET_TEXT: salsa::QueryTypeId = salsa::QueryTypeId(1);
11const GET_FILES: salsa::QueryTypeId = salsa::QueryTypeId(2); 12const GET_FILES: salsa::QueryTypeId = salsa::QueryTypeId(2);
12const FILE_NEWLINES: salsa::QueryTypeId = salsa::QueryTypeId(3); 13const FILE_NEWLINES: salsa::QueryTypeId = salsa::QueryTypeId(3);
@@ -14,9 +15,9 @@ const TOTAL_NEWLINES: salsa::QueryTypeId = salsa::QueryTypeId(4);
14 15
15fn mk_ground_query<T, R>( 16fn mk_ground_query<T, R>(
16 state: &State, 17 state: &State,
17 params: &(Any + Send + Sync + 'static), 18 params: &Data,
18 f: fn(&State, &T) -> R, 19 f: fn(&State, &T) -> R,
19) -> (Box<Any + Send + Sync + 'static>, salsa::OutputFingerprint) 20) -> (Data, salsa::OutputFingerprint)
20where 21where
21 T: 'static, 22 T: 'static,
22 R: Hash + Send + Sync + 'static, 23 R: Hash + Send + Sync + 'static,
@@ -24,21 +25,21 @@ where
24 let params = params.downcast_ref().unwrap(); 25 let params = params.downcast_ref().unwrap();
25 let result = f(state, params); 26 let result = f(state, params);
26 let fingerprint = o_print(&result); 27 let fingerprint = o_print(&result);
27 (Box::new(result), fingerprint) 28 (Arc::new(result), fingerprint)
28} 29}
29 30
30fn get<T, R>(db: &salsa::Db<State>, query_type: salsa::QueryTypeId, param: T) -> (Arc<R>, Vec<salsa::QueryTypeId>) 31fn get<T, R>(db: &salsa::Db<State, Data>, query_type: salsa::QueryTypeId, param: T) -> (Arc<R>, Vec<salsa::QueryTypeId>)
31where 32where
32 T: Hash + Send + Sync + 'static, 33 T: Hash + Send + Sync + 'static,
33 R: Send + Sync + 'static, 34 R: Send + Sync + 'static,
34{ 35{
35 let i_print = i_print(&param); 36 let i_print = i_print(&param);
36 let param = Box::new(param); 37 let param = Arc::new(param);
37 let (res, trace) = db.get(salsa::QueryId(query_type, i_print), param); 38 let (res, trace) = db.get(salsa::QueryId(query_type, i_print), param);
38 (res.downcast().unwrap(), trace) 39 (res.downcast().unwrap(), trace)
39} 40}
40 41
41struct QueryCtx<'a>(&'a salsa::QueryCtx<State>); 42struct QueryCtx<'a>(&'a salsa::QueryCtx<State, Data>);
42 43
43impl<'a> QueryCtx<'a> { 44impl<'a> QueryCtx<'a> {
44 fn get_text(&self, id: u32) -> Arc<String> { 45 fn get_text(&self, id: u32) -> Arc<String> {
@@ -60,10 +61,10 @@ impl<'a> QueryCtx<'a> {
60} 61}
61 62
62fn mk_query<T, R>( 63fn mk_query<T, R>(
63 query_ctx: &salsa::QueryCtx<State>, 64 query_ctx: &salsa::QueryCtx<State, Data>,
64 params: &(Any + Send + Sync + 'static), 65 params: &Data,
65 f: fn(QueryCtx, &T) -> R, 66 f: fn(QueryCtx, &T) -> R,
66) -> (Box<Any + Send + Sync + 'static>, salsa::OutputFingerprint) 67) -> (Data, salsa::OutputFingerprint)
67where 68where
68 T: 'static, 69 T: 'static,
69 R: Hash + Send + Sync + 'static, 70 R: Hash + Send + Sync + 'static,
@@ -72,11 +73,11 @@ where
72 let query_ctx = QueryCtx(query_ctx); 73 let query_ctx = QueryCtx(query_ctx);
73 let result = f(query_ctx, params); 74 let result = f(query_ctx, params);
74 let fingerprint = o_print(&result); 75 let fingerprint = o_print(&result);
75 (Box::new(result), fingerprint) 76 (Arc::new(result), fingerprint)
76} 77}
77 78
78fn mk_queries() -> salsa::QueryConfig<State> { 79fn mk_queries() -> salsa::QueryConfig<State, Data> {
79 salsa::QueryConfig::<State>::new() 80 salsa::QueryConfig::<State, Data>::new()
80 .with_ground_query(GET_TEXT, |state, id| { 81 .with_ground_query(GET_TEXT, |state, id| {
81 mk_ground_query::<u32, String>(state, id, |state, id| state[id].clone()) 82 mk_ground_query::<u32, String>(state, id, |state, id| state[id].clone())
82 }) 83 })