From 4fc5b3eb10a18a492f22f1533f6882812ebf81b8 Mon Sep 17 00:00:00 2001 From: Ziyang Hu Date: Sat, 12 Nov 2022 20:07:30 +0800 Subject: [PATCH] add lifetime on sessiontx --- cozo-core/src/algo/all_pairs_shortest_path.rs | 4 ++-- cozo-core/src/algo/astar.rs | 4 ++-- cozo-core/src/algo/bfs.rs | 2 +- cozo-core/src/algo/constant.rs | 2 +- cozo-core/src/algo/csv.rs | 2 +- cozo-core/src/algo/degree_centrality.rs | 2 +- cozo-core/src/algo/dfs.rs | 2 +- cozo-core/src/algo/jlines.rs | 2 +- cozo-core/src/algo/kruskal.rs | 2 +- cozo-core/src/algo/label_propagation.rs | 2 +- cozo-core/src/algo/louvain.rs | 2 +- cozo-core/src/algo/mod.rs | 12 +++++------ cozo-core/src/algo/pagerank.rs | 2 +- cozo-core/src/algo/prim.rs | 2 +- cozo-core/src/algo/random_walk.rs | 2 +- cozo-core/src/algo/reorder_sort.rs | 2 +- cozo-core/src/algo/shortest_path_dijkstra.rs | 2 +- .../src/algo/strongly_connected_components.rs | 2 +- cozo-core/src/algo/top_sort.rs | 2 +- cozo-core/src/algo/triangles.rs | 2 +- cozo-core/src/algo/yen.rs | 2 +- cozo-core/src/data/program.rs | 4 ++-- cozo-core/src/query/compile.rs | 2 +- cozo-core/src/query/eval.rs | 2 +- cozo-core/src/query/logical.rs | 6 +++--- cozo-core/src/query/magic.rs | 4 ++-- cozo-core/src/query/relation.rs | 20 +++++++++---------- cozo-core/src/query/sort.rs | 2 +- cozo-core/src/query/stored.rs | 7 ++----- cozo-core/src/runtime/db.rs | 19 ++++++------------ cozo-core/src/runtime/relation.rs | 8 ++++---- cozo-core/src/runtime/transact.rs | 6 +++--- 32 files changed, 63 insertions(+), 73 deletions(-) diff --git a/cozo-core/src/algo/all_pairs_shortest_path.rs b/cozo-core/src/algo/all_pairs_shortest_path.rs index 6872ecdd..219be180 100644 --- a/cozo-core/src/algo/all_pairs_shortest_path.rs +++ b/cozo-core/src/algo/all_pairs_shortest_path.rs @@ -29,7 +29,7 @@ pub(crate) struct BetweennessCentrality; impl AlgoImpl for BetweennessCentrality { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, @@ -99,7 +99,7 @@ pub(crate) struct ClosenessCentrality; impl AlgoImpl for ClosenessCentrality { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/astar.rs b/cozo-core/src/algo/astar.rs index f3fa9a59..b10fb8a4 100644 --- a/cozo-core/src/algo/astar.rs +++ b/cozo-core/src/algo/astar.rs @@ -26,7 +26,7 @@ pub(crate) struct ShortestPathAStar; impl AlgoImpl for ShortestPathAStar { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, @@ -87,7 +87,7 @@ fn astar<'a>( edges: &'a MagicAlgoRuleArg, nodes: &'a MagicAlgoRuleArg, heuristic: &Expr, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, stores: &'a BTreeMap, poison: Poison, ) -> Result<(f64, Vec)> { diff --git a/cozo-core/src/algo/bfs.rs b/cozo-core/src/algo/bfs.rs index 5fa5ef06..6c27c607 100644 --- a/cozo-core/src/algo/bfs.rs +++ b/cozo-core/src/algo/bfs.rs @@ -23,7 +23,7 @@ pub(crate) struct Bfs; impl AlgoImpl for Bfs { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/constant.rs b/cozo-core/src/algo/constant.rs index 848b1830..a552f483 100644 --- a/cozo-core/src/algo/constant.rs +++ b/cozo-core/src/algo/constant.rs @@ -24,7 +24,7 @@ pub(crate) struct Constant; impl AlgoImpl for Constant { fn run( &mut self, - _tx: &SessionTx, + _tx: &SessionTx<'_>, algo: &MagicAlgoApply, _stores: &BTreeMap, out: &InMemRelation, diff --git a/cozo-core/src/algo/csv.rs b/cozo-core/src/algo/csv.rs index 3baea0dd..7ebf3aa9 100644 --- a/cozo-core/src/algo/csv.rs +++ b/cozo-core/src/algo/csv.rs @@ -29,7 +29,7 @@ pub(crate) struct CsvReader; impl AlgoImpl for CsvReader { fn run( &mut self, - _tx: &SessionTx, + _tx: &SessionTx<'_>, algo: &MagicAlgoApply, _stores: &BTreeMap, out: &InMemRelation, diff --git a/cozo-core/src/algo/degree_centrality.rs b/cozo-core/src/algo/degree_centrality.rs index f13ac886..c857842e 100644 --- a/cozo-core/src/algo/degree_centrality.rs +++ b/cozo-core/src/algo/degree_centrality.rs @@ -23,7 +23,7 @@ pub(crate) struct DegreeCentrality; impl AlgoImpl for DegreeCentrality { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/dfs.rs b/cozo-core/src/algo/dfs.rs index e44466dd..1513d52f 100644 --- a/cozo-core/src/algo/dfs.rs +++ b/cozo-core/src/algo/dfs.rs @@ -23,7 +23,7 @@ pub(crate) struct Dfs; impl AlgoImpl for Dfs { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/jlines.rs b/cozo-core/src/algo/jlines.rs index e5e99455..3788323c 100644 --- a/cozo-core/src/algo/jlines.rs +++ b/cozo-core/src/algo/jlines.rs @@ -31,7 +31,7 @@ pub(crate) struct JsonReader; impl AlgoImpl for JsonReader { fn run( &mut self, - _tx: &SessionTx, + _tx: &SessionTx<'_>, algo: &MagicAlgoApply, _stores: &BTreeMap, out: &InMemRelation, diff --git a/cozo-core/src/algo/kruskal.rs b/cozo-core/src/algo/kruskal.rs index 6a822cbb..810c0818 100644 --- a/cozo-core/src/algo/kruskal.rs +++ b/cozo-core/src/algo/kruskal.rs @@ -27,7 +27,7 @@ pub(crate) struct MinimumSpanningForestKruskal; impl AlgoImpl for MinimumSpanningForestKruskal { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/label_propagation.rs b/cozo-core/src/algo/label_propagation.rs index 61c09d60..8ad99198 100644 --- a/cozo-core/src/algo/label_propagation.rs +++ b/cozo-core/src/algo/label_propagation.rs @@ -25,7 +25,7 @@ pub(crate) struct LabelPropagation; impl AlgoImpl for LabelPropagation { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/louvain.rs b/cozo-core/src/algo/louvain.rs index 2883fad6..55169985 100644 --- a/cozo-core/src/algo/louvain.rs +++ b/cozo-core/src/algo/louvain.rs @@ -25,7 +25,7 @@ pub(crate) struct CommunityDetectionLouvain; impl AlgoImpl for CommunityDetectionLouvain { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/mod.rs b/cozo-core/src/algo/mod.rs index 55db7d74..806facda 100644 --- a/cozo-core/src/algo/mod.rs +++ b/cozo-core/src/algo/mod.rs @@ -62,7 +62,7 @@ pub(crate) mod yen; pub(crate) trait AlgoImpl { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, @@ -195,7 +195,7 @@ impl MagicAlgoRuleArg { &'a self, undirected: bool, allow_negative_edges: bool, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, stores: &'a BTreeMap, ) -> Result<( Vec>, @@ -279,7 +279,7 @@ impl MagicAlgoRuleArg { pub(crate) fn convert_edge_to_graph<'a>( &'a self, undirected: bool, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, stores: &'a BTreeMap, ) -> Result<(Vec>, Vec, BTreeMap)> { let mut graph: Vec> = vec![]; @@ -319,7 +319,7 @@ impl MagicAlgoRuleArg { pub(crate) fn prefix_iter<'a>( &'a self, prefix: &DataValue, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, stores: &'a BTreeMap, ) -> Result> { Ok(match self { @@ -339,7 +339,7 @@ impl MagicAlgoRuleArg { } pub(crate) fn arity( &self, - tx: &SessionTx, + tx: &SessionTx<'_>, stores: &BTreeMap, ) -> Result { Ok(match self { @@ -357,7 +357,7 @@ impl MagicAlgoRuleArg { } pub(crate) fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, stores: &'a BTreeMap, ) -> Result> { Ok(match self { diff --git a/cozo-core/src/algo/pagerank.rs b/cozo-core/src/algo/pagerank.rs index 854e6430..ef103aaa 100644 --- a/cozo-core/src/algo/pagerank.rs +++ b/cozo-core/src/algo/pagerank.rs @@ -26,7 +26,7 @@ pub(crate) struct PageRank; impl AlgoImpl for PageRank { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/prim.rs b/cozo-core/src/algo/prim.rs index 7e5db062..b956f51b 100644 --- a/cozo-core/src/algo/prim.rs +++ b/cozo-core/src/algo/prim.rs @@ -28,7 +28,7 @@ pub(crate) struct MinimumSpanningTreePrim; impl AlgoImpl for MinimumSpanningTreePrim { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/random_walk.rs b/cozo-core/src/algo/random_walk.rs index dcdc73df..dfa00d3c 100644 --- a/cozo-core/src/algo/random_walk.rs +++ b/cozo-core/src/algo/random_walk.rs @@ -26,7 +26,7 @@ pub(crate) struct RandomWalk; impl AlgoImpl for RandomWalk { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/reorder_sort.rs b/cozo-core/src/algo/reorder_sort.rs index 443d474f..ce7c0c3c 100644 --- a/cozo-core/src/algo/reorder_sort.rs +++ b/cozo-core/src/algo/reorder_sort.rs @@ -25,7 +25,7 @@ pub(crate) struct ReorderSort; impl AlgoImpl for ReorderSort { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/shortest_path_dijkstra.rs b/cozo-core/src/algo/shortest_path_dijkstra.rs index 01fa7583..b980e0dd 100644 --- a/cozo-core/src/algo/shortest_path_dijkstra.rs +++ b/cozo-core/src/algo/shortest_path_dijkstra.rs @@ -30,7 +30,7 @@ pub(crate) struct ShortestPathDijkstra; impl AlgoImpl for ShortestPathDijkstra { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/strongly_connected_components.rs b/cozo-core/src/algo/strongly_connected_components.rs index 612b3db1..551c9a1e 100644 --- a/cozo-core/src/algo/strongly_connected_components.rs +++ b/cozo-core/src/algo/strongly_connected_components.rs @@ -33,7 +33,7 @@ impl StronglyConnectedComponent { impl AlgoImpl for StronglyConnectedComponent { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/top_sort.rs b/cozo-core/src/algo/top_sort.rs index c1672f48..10dbb49d 100644 --- a/cozo-core/src/algo/top_sort.rs +++ b/cozo-core/src/algo/top_sort.rs @@ -23,7 +23,7 @@ pub(crate) struct TopSort; impl AlgoImpl for TopSort { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/triangles.rs b/cozo-core/src/algo/triangles.rs index aecb6a36..3b3da42a 100644 --- a/cozo-core/src/algo/triangles.rs +++ b/cozo-core/src/algo/triangles.rs @@ -24,7 +24,7 @@ pub(crate) struct ClusteringCoefficients; impl AlgoImpl for ClusteringCoefficients { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/algo/yen.rs b/cozo-core/src/algo/yen.rs index fccc4df1..a3cb3957 100644 --- a/cozo-core/src/algo/yen.rs +++ b/cozo-core/src/algo/yen.rs @@ -26,7 +26,7 @@ pub(crate) struct KShortestPathYen; impl AlgoImpl for KShortestPathYen { fn run<'a>( &mut self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, algo: &'a MagicAlgoApply, stores: &'a BTreeMap, out: &'a InMemRelation, diff --git a/cozo-core/src/data/program.rs b/cozo-core/src/data/program.rs index d9e6f3d4..1a72605b 100644 --- a/cozo-core/src/data/program.rs +++ b/cozo-core/src/data/program.rs @@ -271,7 +271,7 @@ impl MagicAlgoApply { &self, idx: usize, len: usize, - tx: &SessionTx, + tx: &SessionTx<'_>, stores: &BTreeMap, ) -> Result<&MagicAlgoRuleArg> { #[derive(Error, Diagnostic, Debug)] @@ -748,7 +748,7 @@ impl InputProgram { Err(NoEntryError.into()) } - pub(crate) fn to_normalized_program(&self, tx: &SessionTx) -> Result { + pub(crate) fn to_normalized_program(&self, tx: &SessionTx<'_>) -> Result { let mut prog: BTreeMap = Default::default(); for (k, rules_or_algo) in &self.prog { match rules_or_algo { diff --git a/cozo-core/src/query/compile.rs b/cozo-core/src/query/compile.rs index 98297a41..3a683d03 100644 --- a/cozo-core/src/query/compile.rs +++ b/cozo-core/src/query/compile.rs @@ -85,7 +85,7 @@ struct RuleNotFound(String, #[label] SourceSpan); #[diagnostic(help("Required arity: {1}, number of arguments given: {2}"))] struct ArityMismatch(String, usize, usize, #[label] SourceSpan); -impl SessionTx { +impl<'a> SessionTx<'a> { pub(crate) fn stratified_magic_compile( &mut self, prog: &StratifiedMagicProgram, diff --git a/cozo-core/src/query/eval.rs b/cozo-core/src/query/eval.rs index 8e1c4abd..97efb072 100644 --- a/cozo-core/src/query/eval.rs +++ b/cozo-core/src/query/eval.rs @@ -39,7 +39,7 @@ impl QueryLimiter { } } -impl SessionTx { +impl<'a> SessionTx<'a> { pub(crate) fn stratified_magic_evaluate( &self, strata: &[CompiledProgram], diff --git a/cozo-core/src/query/logical.rs b/cozo-core/src/query/logical.rs index 350ed7cb..ee021408 100644 --- a/cozo-core/src/query/logical.rs +++ b/cozo-core/src/query/logical.rs @@ -121,7 +121,7 @@ impl InputAtom { }) } - pub(crate) fn disjunctive_normal_form(self, tx: &SessionTx) -> Result { + pub(crate) fn disjunctive_normal_form(self, tx: &SessionTx<'_>) -> Result { let neg_form = self.negation_normal_form()?; let mut gen = TempSymbGen::default(); neg_form.do_disjunctive_normal_form(&mut gen, tx) @@ -134,7 +134,7 @@ impl InputAtom { span, }: InputNamedFieldRelationApplyAtom, gen: &mut TempSymbGen, - tx: &SessionTx, + tx: &SessionTx<'_>, ) -> Result { let stored = tx.get_relation(&name, false)?; let fields: BTreeSet<_> = stored @@ -173,7 +173,7 @@ impl InputAtom { fn do_disjunctive_normal_form( self, gen: &mut TempSymbGen, - tx: &SessionTx, + tx: &SessionTx<'_>, ) -> Result { // invariants: the input is already in negation normal form // the return value is a disjunction of conjunctions, with no nesting diff --git a/cozo-core/src/query/magic.rs b/cozo-core/src/query/magic.rs index b2e98067..485bb1a5 100644 --- a/cozo-core/src/query/magic.rs +++ b/cozo-core/src/query/magic.rs @@ -42,7 +42,7 @@ impl NormalFormProgram { } impl StratifiedNormalFormProgram { - pub(crate) fn magic_sets_rewrite(self, tx: &SessionTx) -> Result { + pub(crate) fn magic_sets_rewrite(self, tx: &SessionTx<'_>) -> Result { let mut exempt_rules = BTreeSet::from([Symbol::new(PROG_ENTRY, SourceSpan(0, 0))]); let mut collected = vec![]; for prog in self.0 { @@ -278,7 +278,7 @@ impl NormalFormProgram { } downstream_rules } - fn adorn(&self, upstream_rules: &BTreeSet, tx: &SessionTx) -> Result { + fn adorn(&self, upstream_rules: &BTreeSet, tx: &SessionTx<'_>) -> Result { let rules_to_rewrite: BTreeSet<_> = self .prog .keys() diff --git a/cozo-core/src/query/relation.rs b/cozo-core/src/query/relation.rs index e3373715..5d724a09 100644 --- a/cozo-core/src/query/relation.rs +++ b/cozo-core/src/query/relation.rs @@ -106,7 +106,7 @@ impl UnificationRA { fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, epoch: Option, use_delta: &BTreeSet, ) -> Result> { @@ -196,7 +196,7 @@ impl FilteredRA { } fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, epoch: Option, use_delta: &BTreeSet, ) -> Result> { @@ -542,7 +542,7 @@ impl ReorderRA { } fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, epoch: Option, use_delta: &BTreeSet, ) -> Result> { @@ -748,7 +748,7 @@ impl StoredRA { fn prefix_join<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, left_iter: TupleIter<'a>, (left_join_indices, right_join_indices): (Vec, Vec), eliminate_indices: BTreeSet, @@ -827,7 +827,7 @@ impl StoredRA { fn neg_join<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, left_iter: TupleIter<'a>, (left_join_indices, right_join_indices): (Vec, Vec), eliminate_indices: BTreeSet, @@ -935,7 +935,7 @@ impl StoredRA { } } - fn iter<'a>(&'a self, tx: &'a SessionTx) -> Result> { + fn iter<'a>(&'a self, tx: &'a SessionTx<'_>) -> Result> { let it = self.storage.scan_all(tx); Ok(if self.filters.is_empty() { Box::new(it) @@ -1308,7 +1308,7 @@ impl RelAlgebra { } pub(crate) fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, epoch: Option, use_delta: &BTreeSet, ) -> Result> { @@ -1386,7 +1386,7 @@ impl NegJoin { pub(crate) fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, epoch: Option, use_delta: &BTreeSet, ) -> Result> { @@ -1512,7 +1512,7 @@ impl InnerJoin { } pub(crate) fn iter<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, epoch: Option, use_delta: &BTreeSet, ) -> Result> { @@ -1585,7 +1585,7 @@ impl InnerJoin { } fn materialized_join<'a>( &'a self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, eliminate_indices: BTreeSet, epoch: Option, use_delta: &BTreeSet, diff --git a/cozo-core/src/query/sort.rs b/cozo-core/src/query/sort.rs index 80166afa..da8a8a09 100644 --- a/cozo-core/src/query/sort.rs +++ b/cozo-core/src/query/sort.rs @@ -14,7 +14,7 @@ use crate::data::tuple::Tuple; use crate::runtime::in_mem::InMemRelation; use crate::runtime::transact::SessionTx; -impl SessionTx { +impl<'a> SessionTx<'a> { pub(crate) fn sort_and_collect( &mut self, original: InMemRelation, diff --git a/cozo-core/src/query/stored.rs b/cozo-core/src/query/stored.rs index 3e52e2b4..a769df9f 100644 --- a/cozo-core/src/query/stored.rs +++ b/cozo-core/src/query/stored.rs @@ -28,7 +28,7 @@ use crate::Db; #[diagnostic(code(eval::relation_arity_mismatch))] struct RelationArityMismatch(String, usize, usize); -impl SessionTx { +impl<'a> SessionTx<'a> { pub(crate) fn execute_relation( &mut self, db: &Db, @@ -36,10 +36,7 @@ impl SessionTx { op: RelationOp, meta: &InputRelationHandle, headers: &[Symbol], - ) -> Result, Vec)>> - where - ::Tx: 'static, - { + ) -> Result, Vec)>> { let mut to_clear = vec![]; let mut replaced_old_triggers = None; if op == RelationOp::Replace { diff --git a/cozo-core/src/runtime/db.rs b/cozo-core/src/runtime/db.rs index 51a0c34b..dc4b7d34 100644 --- a/cozo-core/src/runtime/db.rs +++ b/cozo-core/src/runtime/db.rs @@ -71,10 +71,7 @@ pub struct Db { running_queries: Arc>>, } -impl Debug for Db -where - S: Storage, -{ +impl Debug for Db { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { write!(f, "Db") } @@ -91,11 +88,7 @@ lazy_static! { static ref JSON_ERR_HANDLER: JSONReportHandler = miette::JSONReportHandler::new(); } -impl Db -where - S: Storage, - ::Tx: 'static, -{ +impl Db { /// create a new database with the specified storage pub fn new(storage: S) -> Result { let ret = Self { @@ -121,7 +114,7 @@ where tx.commit_tx()?; Ok(()) } - fn transact(&self) -> Result { + fn transact(&self) -> Result> { let ret = SessionTx { tx: Box::new(self.db.transact(false)?), mem_store_id: Default::default(), @@ -129,7 +122,7 @@ where }; Ok(ret) } - fn transact_write(&self) -> Result { + fn transact_write(&self) -> Result> { let ret = SessionTx { tx: Box::new(self.db.transact(true)?), mem_store_id: Default::default(), @@ -492,7 +485,7 @@ where } pub(crate) fn run_query( &self, - tx: &mut SessionTx, + tx: &mut SessionTx<'_>, input_program: InputProgram, ) -> Result<(JsonValue, Vec<(Vec, Vec)>)> { let mut clean_ups = vec![]; @@ -670,7 +663,7 @@ where } } } - pub(crate) fn remove_relation(&self, name: &Symbol, tx: &mut SessionTx) -> Result<()> { + pub(crate) fn remove_relation(&self, name: &Symbol, tx: &mut SessionTx<'_>) -> Result<()> { let (lower, upper) = tx.destroy_relation(name)?; self.db.del_range(&lower, &upper)?; Ok(()) diff --git a/cozo-core/src/runtime/relation.rs b/cozo-core/src/runtime/relation.rs index 208ac643..da84009b 100644 --- a/cozo-core/src/runtime/relation.rs +++ b/cozo-core/src/runtime/relation.rs @@ -214,7 +214,7 @@ impl RelationHandle { RelationDeserError })?) } - pub(crate) fn scan_all<'a>(&self, tx: &'a SessionTx) -> impl Iterator> + 'a { + pub(crate) fn scan_all<'a>(&self, tx: &'a SessionTx<'_>) -> impl Iterator> + 'a { let lower = Tuple::default().encode_as_key(self.id); let upper = Tuple::default().encode_as_key(self.id.next()); tx.tx.range_scan(&lower, &upper) @@ -222,7 +222,7 @@ impl RelationHandle { pub(crate) fn scan_prefix<'a>( &self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, prefix: &Tuple, ) -> impl Iterator> + 'a { let mut lower = prefix.0.clone(); @@ -236,7 +236,7 @@ impl RelationHandle { } pub(crate) fn scan_bounded_prefix<'a>( &self, - tx: &'a SessionTx, + tx: &'a SessionTx<'_>, prefix: &Tuple, lower: &[DataValue], upper: &[DataValue], @@ -267,7 +267,7 @@ pub(crate) fn decode_tuple_from_kv(key: &[u8], val: &[u8]) -> Tuple { #[diagnostic(code(eval::rel_name_conflict))] struct RelNameConflictError(String); -impl SessionTx { +impl<'a> SessionTx<'a> { pub(crate) fn relation_exists(&self, name: &str) -> Result { let key = DataValue::Str(SmartString::from(name)); let encoded = Tuple(vec![key]).encode_as_key(RelationId::SYSTEM); diff --git a/cozo-core/src/runtime/transact.rs b/cozo-core/src/runtime/transact.rs index 458a90ce..7abe19d7 100644 --- a/cozo-core/src/runtime/transact.rs +++ b/cozo-core/src/runtime/transact.rs @@ -16,13 +16,13 @@ use crate::runtime::in_mem::{InMemRelation, StoredRelationId}; use crate::runtime::relation::RelationId; use crate::storage::StoreTx; -pub struct SessionTx { - pub(crate) tx: Box, +pub struct SessionTx<'a> { + pub(crate) tx: Box, pub(crate) relation_store_id: Arc, pub(crate) mem_store_id: Arc, } -impl SessionTx { +impl<'a> SessionTx<'a> { pub(crate) fn new_rule_store(&self, rule_name: MagicSymbol, arity: usize) -> InMemRelation { let old_count = self.mem_store_id.fetch_add(1, Ordering::AcqRel); let old_count = old_count & 0x00ff_ffffu32;