From 0ff5ea7860478d60e4014824eb2b2f9548327a6c Mon Sep 17 00:00:00 2001 From: elvis Date: Fri, 31 Oct 2025 16:36:28 +0100 Subject: [PATCH] All structures thread safe --- execution/src/presets.rs | 18 ++-- grammar/src/grammar.lalrpop | 18 ++-- grammar_separated/src/grammar.lalrpop | 28 +++--- rsprocess/src/choices.rs | 56 ++++++------ rsprocess/src/environment.rs | 42 ++++----- rsprocess/src/format_helpers.rs | 108 +++++++++++----------- rsprocess/src/graph.rs | 126 +++++++++++++------------- rsprocess/src/process.rs | 46 +++++----- rsprocess/src/reaction.rs | 7 ++ rsprocess/src/set.rs | 23 +++++ rsprocess/src/system.rs | 119 ++++++++++++------------ rsprocess/src/system_test.rs | 109 ++++++++++------------ rsprocess/src/trace.rs | 30 +++--- rsprocess/src/trace_test.rs | 20 ++-- rsprocess/src/transitions.rs | 20 ++-- 15 files changed, 391 insertions(+), 379 deletions(-) diff --git a/execution/src/presets.rs b/execution/src/presets.rs index e5f5785..e894151 100644 --- a/execution/src/presets.rs +++ b/execution/src/presets.rs @@ -1,6 +1,6 @@ //! Module that holds useful presets for interacting with other modules. use std::io::prelude::*; -use std::rc::Rc; +use std::sync::Arc; use std::{env, fs, io}; use petgraph::Graph; @@ -719,17 +719,17 @@ pub fn dot( edge_color: graph::EdgeColor, ) -> Result { if let Some(graph) = &system.graph { - let rc_translator = Rc::new(system.translator.clone()); + let rc_translator = Arc::new(system.translator.clone()); let modified_graph = graph.map( - node_display.generate(Rc::clone(&rc_translator), graph), - edge_display.generate(Rc::clone(&rc_translator), graph), + node_display.generate(Arc::clone(&rc_translator), graph), + edge_display.generate(Arc::clone(&rc_translator), graph), ); - let graph = Rc::new(graph.to_owned()); + let graph = Arc::new(graph.to_owned()); let node_formatter = node_color - .generate(Rc::clone(&graph), system.translator.encode_not_mut("*")); - let edge_formatter = edge_color.generate(Rc::clone(&graph)); + .generate(Arc::clone(&graph), system.translator.encode_not_mut("*")); + let edge_formatter = edge_color.generate(Arc::clone(&graph)); let dot = dot::Dot::with_attr_getters( &modified_graph, @@ -751,11 +751,11 @@ pub fn graphml( edge_display: graph::EdgeDisplay, ) -> Result { if let Some(graph) = &system.graph { - let rc_translator = Rc::new(system.translator.to_owned()); + let rc_translator = Arc::new(system.translator.to_owned()); // map each value to the corresponding value we want to display let modified_graph = graph.map( - node_display.generate(Rc::clone(&rc_translator), graph), + node_display.generate(Arc::clone(&rc_translator), graph), edge_display.generate(rc_translator, graph), ); diff --git a/grammar/src/grammar.lalrpop b/grammar/src/grammar.lalrpop index 9ca3b88..4db4df7 100644 --- a/grammar/src/grammar.lalrpop +++ b/grammar/src/grammar.lalrpop @@ -1,4 +1,4 @@ -use std::rc::Rc; +use std::sync::Arc; use std::str::FromStr; use lalrpop_util::ParseError; @@ -263,30 +263,30 @@ Context: process::Process = { process::Process::NondeterministicChoice{ children: t } }; -Boxed_CTX_process: Rc = { - => Rc::new(t) +Boxed_CTX_process: Arc = { + => Arc::new(t) } CTX_process: process::Process = { "nill" => process::Process::Nill, "." => - process::Process::EntitySet{ entities: c, next_process: Rc::new(k) }, + process::Process::EntitySet{ entities: c, next_process: Arc::new(k) }, "(" ")" => k, "(" > ")" => process::Process::Summation{ - children: k.into_iter().map(Rc::new).collect::>() + children: k.into_iter().map(Arc::new).collect::>() }, "?" "?" "." => - process::Process::Guarded{ reaction: r, next_process: Rc::new(k) }, + process::Process::Guarded{ reaction: r, next_process: Arc::new(k) }, "<" "," ">" "." => process::Process::WaitEntity{ repeat: n, - repeated_process: Rc::new(k1), - next_process: Rc::new(k) }, + repeated_process: Arc::new(k1), + next_process: Arc::new(k) }, => process::Process::RecursiveIdentifier{ @@ -726,7 +726,7 @@ System: system::System = { => system::System::from(delta.into(), available_entities, context_process, - Rc::new(reaction_rules)) + Arc::new(reaction_rules)) } // experiment diff --git a/grammar_separated/src/grammar.lalrpop b/grammar_separated/src/grammar.lalrpop index af48077..b205b79 100644 --- a/grammar_separated/src/grammar.lalrpop +++ b/grammar_separated/src/grammar.lalrpop @@ -1,4 +1,4 @@ -use std::rc::Rc; +use std::sync::Arc; use std::str::FromStr; use lalrpop_util::ParseError; @@ -245,7 +245,7 @@ PositiveReaction: reaction::PositiveReaction = { pub Context: process::Process = { > => process::Process::NondeterministicChoice{ - children: t.into_iter().map(Rc::new).collect::>() + children: t.into_iter().map(Arc::new).collect::>() } }; @@ -253,22 +253,22 @@ ContextProcess: process::Process = { "nill" => process::Process::Nill, "." => - process::Process::EntitySet{ entities: c, next_process: Rc::new(k) }, + process::Process::EntitySet{ entities: c, next_process: Arc::new(k) }, "(" ")" => k, "(" > ")" => process::Process::Summation{ - children: k.into_iter().map(Rc::new).collect::>() + children: k.into_iter().map(Arc::new).collect::>() }, "?" "?" "." => - process::Process::Guarded{ reaction: r, next_process: Rc::new(k) }, + process::Process::Guarded{ reaction: r, next_process: Arc::new(k) }, "<" "," ">" "." => process::Process::WaitEntity{ repeat: n, - repeated_process: Rc::new(k1), - next_process: Rc::new(k) }, + repeated_process: Arc::new(k1), + next_process: Arc::new(k) }, => process::Process::RecursiveIdentifier{ @@ -279,7 +279,7 @@ ContextProcess: process::Process = { pub PositiveContext: process::PositiveProcess = { > => process::PositiveProcess::NondeterministicChoice{ - children: t.into_iter().map(Rc::new).collect::>() + children: t.into_iter().map(Arc::new).collect::>() } }; @@ -287,22 +287,22 @@ PositiveContextProcess: process::PositiveProcess = { "nill" => process::PositiveProcess::Nill, "." => - process::PositiveProcess::EntitySet{ entities: c, next_process: Rc::new(k) }, + process::PositiveProcess::EntitySet{ entities: c, next_process: Arc::new(k) }, "(" ")" => k, "(" > ")" => process::PositiveProcess::Summation{ - children: k.into_iter().map(Rc::new).collect::>() + children: k.into_iter().map(Arc::new).collect::>() }, "?" "?" "." => - process::PositiveProcess::Guarded{ reaction: r, next_process: Rc::new(k) }, + process::PositiveProcess::Guarded{ reaction: r, next_process: Arc::new(k) }, "<" "," ">" "." => process::PositiveProcess::WaitEntity{ repeat: n, - repeated_process: Rc::new(k1), - next_process: Rc::new(k) }, + repeated_process: Arc::new(k1), + next_process: Arc::new(k) }, => process::PositiveProcess::RecursiveIdentifier{ @@ -367,7 +367,7 @@ pub System: system::System = { => system::System::from(delta.into(), available_entities, context_process, - Rc::new(reaction_rules)) + Arc::new(reaction_rules)) } // experiment diff --git a/rsprocess/src/choices.rs b/rsprocess/src/choices.rs index c8208af..1da50e5 100644 --- a/rsprocess/src/choices.rs +++ b/rsprocess/src/choices.rs @@ -1,5 +1,5 @@ use std::fmt::Debug; -use std::rc::Rc; +use std::sync::Arc; use super::process::{BasicProcess, PositiveProcess, Process}; use super::set::{BasicSet, PositiveSet, Set}; @@ -12,7 +12,7 @@ where type Process: BasicProcess; fn append(&mut self, other: &mut Self); - fn replace(&mut self, other: Rc); + fn replace(&mut self, other: Arc); fn shuffle(&mut self, choices: Self); } @@ -20,7 +20,7 @@ where #[derive(Clone, Debug, Default)] pub struct Choices { - context_moves: Vec<(Rc, Rc)>, + context_moves: Vec<(Arc, Arc)>, } impl BasicChoices for Choices { @@ -30,11 +30,11 @@ impl BasicChoices for Choices { self.context_moves.append(&mut a.context_moves); } - fn replace(&mut self, a: Rc) { + fn replace(&mut self, a: Arc) { self.context_moves = self .context_moves .iter_mut() - .map(|(c1, _)| (Rc::clone(c1), Rc::clone(&a))) + .map(|(c1, _)| (Arc::clone(c1), Arc::clone(&a))) .collect::>(); } @@ -51,8 +51,8 @@ impl BasicChoices for Choices { for item_self in &self.context_moves { for item_choices in &choices.context_moves { new_self.push(( - Rc::new(item_self.0.union(&item_choices.0)), - Rc::new(item_self.1.concat(&item_choices.1)), + Arc::new(item_self.0.union(&item_choices.0)), + Arc::new(item_self.1.concat(&item_choices.1)), )); } } @@ -63,13 +63,13 @@ impl BasicChoices for Choices { } impl Choices { - fn iter(&self) -> std::slice::Iter<'_, (Rc, Rc)> { + fn iter(&self) -> std::slice::Iter<'_, (Arc, Arc)> { self.context_moves.iter() } } impl IntoIterator for Choices { - type Item = (Rc, Rc); + type Item = (Arc, Arc); type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -77,24 +77,24 @@ impl IntoIterator for Choices { } } -impl From<[(Rc, Rc); N]> for Choices { - fn from(arr: [(Rc, Rc); N]) -> Self { +impl From<[(Arc, Arc); N]> for Choices { + fn from(arr: [(Arc, Arc); N]) -> Self { Choices { context_moves: arr.to_vec(), } } } -impl From<&[(Rc, Rc)]> for Choices { - fn from(arr: &[(Rc, Rc)]) -> Self { +impl From<&[(Arc, Arc)]> for Choices { + fn from(arr: &[(Arc, Arc)]) -> Self { Choices { context_moves: arr.to_vec(), } } } -impl From, Rc)>> for Choices { - fn from(arr: Vec<(Rc, Rc)>) -> Self { +impl From, Arc)>> for Choices { + fn from(arr: Vec<(Arc, Arc)>) -> Self { Choices { context_moves: arr } } } @@ -132,7 +132,7 @@ impl PrintableWithTranslator for Choices { #[derive(Clone, Debug, Default)] pub struct PositiveChoices { - context_moves: Vec<(Rc, Rc)>, + context_moves: Vec<(Arc, Arc)>, } impl BasicChoices for PositiveChoices { @@ -142,11 +142,11 @@ impl BasicChoices for PositiveChoices { self.context_moves.append(&mut a.context_moves); } - fn replace(&mut self, a: Rc) { + fn replace(&mut self, a: Arc) { self.context_moves = self .context_moves .iter_mut() - .map(|(c1, _)| (Rc::clone(c1), Rc::clone(&a))) + .map(|(c1, _)| (Arc::clone(c1), Arc::clone(&a))) .collect::>(); } @@ -163,8 +163,8 @@ impl BasicChoices for PositiveChoices { for item_self in &self.context_moves { for item_choices in &choices.context_moves { new_self.push(( - Rc::new(item_self.0.union(&item_choices.0)), - Rc::new(item_self.1.concat(&item_choices.1)), + Arc::new(item_self.0.union(&item_choices.0)), + Arc::new(item_self.1.concat(&item_choices.1)), )); } } @@ -175,7 +175,7 @@ impl BasicChoices for PositiveChoices { } impl IntoIterator for PositiveChoices { - type Item = (Rc, Rc); + type Item = (Arc, Arc); type IntoIter = std::vec::IntoIter; fn into_iter(self) -> Self::IntoIter { @@ -215,31 +215,31 @@ impl PrintableWithTranslator for PositiveChoices { impl PositiveChoices { fn iter( &self, - ) -> std::slice::Iter<'_, (Rc, Rc)> { + ) -> std::slice::Iter<'_, (Arc, Arc)> { self.context_moves.iter() } } -impl From<[(Rc, Rc); N]> +impl From<[(Arc, Arc); N]> for PositiveChoices { - fn from(arr: [(Rc, Rc); N]) -> Self { + fn from(arr: [(Arc, Arc); N]) -> Self { Self { context_moves: arr.to_vec(), } } } -impl From<&[(Rc, Rc)]> for PositiveChoices { - fn from(arr: &[(Rc, Rc)]) -> Self { +impl From<&[(Arc, Arc)]> for PositiveChoices { + fn from(arr: &[(Arc, Arc)]) -> Self { Self { context_moves: arr.to_vec(), } } } -impl From, Rc)>> for PositiveChoices { - fn from(arr: Vec<(Rc, Rc)>) -> Self { +impl From, Arc)>> for PositiveChoices { + fn from(arr: Vec<(Arc, Arc)>) -> Self { Self { context_moves: arr } } } diff --git a/rsprocess/src/environment.rs b/rsprocess/src/environment.rs index 4af67ad..19a4a0f 100644 --- a/rsprocess/src/environment.rs +++ b/rsprocess/src/environment.rs @@ -2,7 +2,7 @@ use std::cmp; use std::collections::{BTreeMap, HashSet}; use std::fmt::Debug; use std::hash::Hash; -use std::rc::Rc; +use std::sync::Arc; use serde::{Deserialize, Serialize}; @@ -304,8 +304,8 @@ impl BasicEnvironment for Environment { entities, next_process, } => Ok(Choices::from([( - Rc::new(entities.clone()), - Rc::clone(next_process), + Arc::new(entities.clone()), + Arc::clone(next_process), )])), | Process::Guarded { reaction, @@ -313,8 +313,8 @@ impl BasicEnvironment for Environment { } => if reaction.enabled(current_entities) { Ok(Choices::from([( - Rc::new(reaction.products.clone()), - Rc::clone(next_process), + Arc::new(reaction.products.clone()), + Arc::clone(next_process), )])) } else { Ok(Choices::default()) @@ -331,7 +331,7 @@ impl BasicEnvironment for Environment { } if *repeat == 1 => { let mut choices1 = self.unfold(repeated_process, current_entities)?; - choices1.replace(Rc::clone(next_process)); + choices1.replace(Arc::clone(next_process)); Ok(choices1) }, | Process::WaitEntity { @@ -341,10 +341,10 @@ impl BasicEnvironment for Environment { } => { let mut choices1 = self.unfold(repeated_process, current_entities)?; - choices1.replace(Rc::new(Process::WaitEntity { + choices1.replace(Arc::new(Process::WaitEntity { repeat: (*repeat - 1), - repeated_process: Rc::clone(repeated_process), - next_process: Rc::clone(next_process), + repeated_process: Arc::clone(repeated_process), + next_process: Arc::clone(next_process), })); Ok(choices1) }, @@ -364,8 +364,8 @@ impl BasicEnvironment for Environment { // short-circuits with try_fold. if children.is_empty() { Ok(Choices::from(vec![( - Rc::new(Set::default()), - Rc::new(Process::Nill), + Arc::new(Set::default()), + Arc::new(Process::Nill), )])) } else { children.iter().try_fold( @@ -670,8 +670,8 @@ impl BasicEnvironment for PositiveEnvironment { entities, next_process, } => Ok(Self::Choices::from([( - Rc::new(entities.clone()), - Rc::clone(next_process), + Arc::new(entities.clone()), + Arc::clone(next_process), )])), | PositiveProcess::Guarded { reaction, @@ -679,8 +679,8 @@ impl BasicEnvironment for PositiveEnvironment { } => if reaction.enabled(entities) { Ok(Self::Choices::from([( - Rc::new(reaction.products.clone()), - Rc::clone(next_process), + Arc::new(reaction.products.clone()), + Arc::clone(next_process), )])) } else { Ok(Self::Choices::default()) @@ -696,7 +696,7 @@ impl BasicEnvironment for PositiveEnvironment { next_process, } if *repeat == 1 => { let mut choices1 = self.unfold(repeated_process, entities)?; - choices1.replace(Rc::clone(next_process)); + choices1.replace(Arc::clone(next_process)); Ok(choices1) }, | PositiveProcess::WaitEntity { @@ -705,10 +705,10 @@ impl BasicEnvironment for PositiveEnvironment { next_process, } => { let mut choices1 = self.unfold(repeated_process, entities)?; - choices1.replace(Rc::new(PositiveProcess::WaitEntity { + choices1.replace(Arc::new(PositiveProcess::WaitEntity { repeat: (*repeat - 1), - repeated_process: Rc::clone(repeated_process), - next_process: Rc::clone(next_process), + repeated_process: Arc::clone(repeated_process), + next_process: Arc::clone(next_process), })); Ok(choices1) }, @@ -729,8 +729,8 @@ impl BasicEnvironment for PositiveEnvironment { // short-circuits with try_fold. if children.is_empty() { Ok(Self::Choices::from(vec![( - Rc::new(Self::Set::default()), - Rc::new(Self::Process::default()), + Arc::new(Self::Set::default()), + Arc::new(Self::Process::default()), )])) } else { children.iter().try_fold( diff --git a/rsprocess/src/format_helpers.rs b/rsprocess/src/format_helpers.rs index 6232999..a7e76ad 100644 --- a/rsprocess/src/format_helpers.rs +++ b/rsprocess/src/format_helpers.rs @@ -1,5 +1,5 @@ pub mod graph_map_nodes_ty_from { - use std::rc::Rc; + use std::sync::Arc; use super::super::set::{BasicSet, Set}; use super::super::system::System; @@ -13,13 +13,13 @@ pub mod graph_map_nodes_ty_from { } pub fn format_hide( - _translator: Rc, + _translator: Arc, ) -> Box { Box::new(|_, _| String::new()) } pub fn format_entities( - translator: Rc, + translator: Arc, ) -> Box { Box::new(move |_, node: &System| { format!( @@ -33,7 +33,7 @@ pub mod graph_map_nodes_ty_from { } pub fn format_mask_entities( - translator: Rc, + translator: Arc, mask: Set, ) -> Box { Box::new(move |_, node: &System| { @@ -46,7 +46,7 @@ pub mod graph_map_nodes_ty_from { } pub fn format_exclude_entities( - translator: Rc, + translator: Arc, mask: Set, ) -> Box { Box::new(move |_, node: &System| { @@ -59,7 +59,7 @@ pub mod graph_map_nodes_ty_from { } pub fn format_context( - translator: Rc, + translator: Arc, ) -> Box { Box::new(move |_, node: &System| { format!( @@ -71,7 +71,7 @@ pub mod graph_map_nodes_ty_from { } pub mod graph_map_edges_ty_from { - use std::rc::Rc; + use std::sync::Arc; use super::super::label::Label; use super::super::set::{BasicSet, Set}; @@ -81,14 +81,14 @@ pub mod graph_map_edges_ty_from { dyn Fn(petgraph::prelude::EdgeIndex, &'a Label) -> String + 'a; pub fn format_string<'a>( - _translator: Rc, + _translator: Arc, s: String, ) -> Box> { Box::new(move |_, _| s.clone()) } pub fn format_hide<'a>( - _translator: Rc, + _translator: Arc, ) -> Box> { Box::new(|_, _| String::new()) } @@ -101,7 +101,7 @@ pub mod graph_map_edges_ty_from { $common:expr, $default:expr ) => { pub fn $name<'a>( - translator: Rc, + translator: Arc, $mask_name: Option, $common_name: Option, ) -> Box> { @@ -235,7 +235,7 @@ pub mod graph_map_edges_ty_from { } pub mod node_formatter { - use std::rc::Rc; + use std::sync::Arc; use petgraph::visit::IntoNodeReferences; use petgraph::{Directed, Graph}; @@ -252,7 +252,7 @@ pub mod node_formatter { ) -> Option; pub fn format_nill( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -267,7 +267,7 @@ pub mod node_formatter { } pub fn format_recursive_identifier( - original_graph: Rc, + original_graph: Arc, color: String, star: Option, s: IdType, @@ -286,7 +286,7 @@ pub mod node_formatter { } pub fn format_entity_set( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ot: OperationType, @@ -306,7 +306,7 @@ pub mod node_formatter { } pub fn format_non_deterministic_choice( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -323,7 +323,7 @@ pub mod node_formatter { } pub fn format_summation( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -339,7 +339,7 @@ pub mod node_formatter { } pub fn format_wait_entity( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -359,7 +359,7 @@ pub mod node_formatter { } pub fn format_entities_conditional( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ot: OperationType, @@ -377,7 +377,7 @@ pub mod node_formatter { } pub mod edge_formatter { - use std::rc::Rc; + use std::sync::Arc; use petgraph::visit::{EdgeRef, IntoEdgeReferences}; use petgraph::{Directed, Graph}; @@ -392,7 +392,7 @@ pub mod edge_formatter { ) -> Option; pub fn format_entities( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -408,7 +408,7 @@ pub mod edge_formatter { } pub fn format_context( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -424,7 +424,7 @@ pub mod edge_formatter { } pub fn format_t( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -440,7 +440,7 @@ pub mod edge_formatter { } pub fn format_reactants( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -456,7 +456,7 @@ pub mod edge_formatter { } pub fn format_reactants_absent( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -472,7 +472,7 @@ pub mod edge_formatter { } pub fn format_inhibitors( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -488,7 +488,7 @@ pub mod edge_formatter { } pub fn format_inhibitors_present( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -504,7 +504,7 @@ pub mod edge_formatter { } pub fn format_products( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -525,7 +525,7 @@ pub mod edge_formatter { // ----------------------------------------------------------------------------- pub mod positive_graph_map_nodes_ty_from { - use std::rc::Rc; + use std::sync::Arc; use super::super::element::IdState; use super::super::set::{BasicSet, Set}; @@ -540,13 +540,13 @@ pub mod positive_graph_map_nodes_ty_from { } pub fn format_hide( - _translator: Rc, + _translator: Arc, ) -> Box { Box::new(|_, _| String::new()) } pub fn format_entities( - translator: Rc, + translator: Arc, ) -> Box { Box::new(move |_, node: &PositiveSystem| { format!( @@ -560,7 +560,7 @@ pub mod positive_graph_map_nodes_ty_from { } pub fn format_mask_entities( - translator: Rc, + translator: Arc, mask: Set, ) -> Box { Box::new(move |_, node: &PositiveSystem| { @@ -575,7 +575,7 @@ pub mod positive_graph_map_nodes_ty_from { } pub fn format_exclude_entities( - translator: Rc, + translator: Arc, mask: Set, ) -> Box { Box::new(move |_, node: &PositiveSystem| { @@ -591,7 +591,7 @@ pub mod positive_graph_map_nodes_ty_from { } pub fn format_context( - translator: Rc, + translator: Arc, ) -> Box { Box::new(move |_, node: &PositiveSystem| { format!( @@ -603,7 +603,7 @@ pub mod positive_graph_map_nodes_ty_from { } pub mod positive_graph_map_edges_ty_from { - use std::rc::Rc; + use std::sync::Arc; use super::super::element::IdState; use super::super::label::PositiveLabel; @@ -614,14 +614,14 @@ pub mod positive_graph_map_edges_ty_from { dyn Fn(petgraph::prelude::EdgeIndex, &'a PositiveLabel) -> String + 'a; pub fn format_string<'a>( - _translator: Rc, + _translator: Arc, s: String, ) -> Box> { Box::new(move |_, _| s.clone()) } pub fn format_hide<'a>( - _translator: Rc, + _translator: Arc, ) -> Box> { Box::new(|_, _| String::new()) } @@ -634,7 +634,7 @@ pub mod positive_graph_map_edges_ty_from { $common:expr, $default:expr ) => { pub fn $name<'a>( - translator: Rc, + translator: Arc, $mask_name: Option, $common_name: Option, ) -> Box> { @@ -812,7 +812,7 @@ pub mod positive_graph_map_edges_ty_from { } pub mod positive_node_formatter { - use std::rc::Rc; + use std::sync::Arc; use petgraph::visit::IntoNodeReferences; use petgraph::{Directed, Graph}; @@ -829,7 +829,7 @@ pub mod positive_node_formatter { ) -> Option; pub fn format_nill( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -844,7 +844,7 @@ pub mod positive_node_formatter { } pub fn format_recursive_identifier( - original_graph: Rc, + original_graph: Arc, color: String, star: Option, s: IdType, @@ -866,7 +866,7 @@ pub mod positive_node_formatter { } pub fn format_entity_set( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ot: OperationType, @@ -886,7 +886,7 @@ pub mod positive_node_formatter { } pub fn format_non_deterministic_choice( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -903,7 +903,7 @@ pub mod positive_node_formatter { } pub fn format_summation( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -920,7 +920,7 @@ pub mod positive_node_formatter { } pub fn format_wait_entity( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ) -> Box { @@ -940,7 +940,7 @@ pub mod positive_node_formatter { } pub fn format_entities_conditional( - original_graph: Rc, + original_graph: Arc, color: String, _star: Option, ot: OperationType, @@ -958,7 +958,7 @@ pub mod positive_node_formatter { } pub mod positive_edge_formatter { - use std::rc::Rc; + use std::sync::Arc; use petgraph::visit::{EdgeRef, IntoEdgeReferences}; use petgraph::{Directed, Graph}; @@ -973,7 +973,7 @@ pub mod positive_edge_formatter { ) -> Option; pub fn format_entities( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -989,7 +989,7 @@ pub mod positive_edge_formatter { } pub fn format_context( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -1005,7 +1005,7 @@ pub mod positive_edge_formatter { } pub fn format_t( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -1021,7 +1021,7 @@ pub mod positive_edge_formatter { } pub fn format_reactants( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -1037,7 +1037,7 @@ pub mod positive_edge_formatter { } pub fn format_reactants_absent( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -1053,7 +1053,7 @@ pub mod positive_edge_formatter { } pub fn format_inhibitors( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -1069,7 +1069,7 @@ pub mod positive_edge_formatter { } pub fn format_inhibitors_present( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, @@ -1085,7 +1085,7 @@ pub mod positive_edge_formatter { } pub fn format_products( - original_graph: Rc, + original_graph: Arc, color: String, ot: OperationType, set: Set, diff --git a/rsprocess/src/graph.rs b/rsprocess/src/graph.rs index 76d5c50..0f5ff09 100644 --- a/rsprocess/src/graph.rs +++ b/rsprocess/src/graph.rs @@ -1,6 +1,6 @@ //! Definitions for generating graphs from a simulation. -use std::rc::Rc; +use std::sync::Arc; use petgraph::visit::{IntoEdgeReferences, IntoNodeReferences}; use petgraph::{Directed, Graph}; @@ -222,8 +222,8 @@ type PositiveGraphMapNodesFnTy<'a> = impl NodeDisplayBase { fn match_node_display<'a>( &self, - common_entities: Rc, - translator: Rc, + common_entities: Arc, + translator: Arc, ) -> Box> { use super::format_helpers::graph_map_nodes_ty_from::*; @@ -247,8 +247,8 @@ impl NodeDisplayBase { fn positive_match_node_display<'a>( &self, - common_entities: Rc, - translator: Rc, + common_entities: Arc, + translator: Arc, ) -> Box> { use super::format_helpers::positive_graph_map_nodes_ty_from::*; @@ -284,21 +284,21 @@ impl NodeDisplay { pub fn generate<'a>( self, - translator: Rc, + translator: Arc, current_graph: &SystemGraph, ) -> Box> { let common_entities = if self.contains_uncommon() { - Rc::new(common_system_entities(current_graph)) + Arc::new(common_system_entities(current_graph)) } else { - Rc::new(Set::default()) + Arc::new(Set::default()) }; Box::new(move |i, n| { let mut accumulator = String::new(); for b in &self.base { let f = b.match_node_display( - Rc::clone(&common_entities), - Rc::clone(&translator), + Arc::clone(&common_entities), + Arc::clone(&translator), ); accumulator.push_str(&(f)(i, n)); @@ -309,21 +309,21 @@ impl NodeDisplay { pub fn generate_positive<'a>( self, - translator: Rc, + translator: Arc, current_graph: &PositiveSystemGraph, ) -> Box> { let common_entities = if self.contains_uncommon() { - Rc::new(positive_common_system_entities(current_graph)) + Arc::new(positive_common_system_entities(current_graph)) } else { - Rc::new(Set::default()) + Arc::new(Set::default()) }; Box::new(move |i, n| { let mut accumulator = String::new(); for b in &self.base { let f = b.positive_match_node_display( - Rc::clone(&common_entities), - Rc::clone(&translator), + Arc::clone(&common_entities), + Arc::clone(&translator), ); accumulator.push_str(&(f)(i, n)); @@ -396,7 +396,7 @@ struct CommonEntities { impl EdgeDisplayBase { fn match_edge_display<'a>( &'a self, - translator: Rc, + translator: Arc, common: CommonEntities, ) -> Box> { use super::format_helpers::graph_map_edges_ty_from::*; @@ -501,7 +501,7 @@ impl EdgeDisplayBase { fn positive_match_edge_display<'a>( &'a self, - translator: Rc, + translator: Arc, common: CommonEntities, ) -> Box> { use super::format_helpers::positive_graph_map_edges_ty_from::*; @@ -679,7 +679,7 @@ impl EdgeDisplay { pub fn generate<'a>( self, - translator: Rc, + translator: Arc, current_graph: &SystemGraph, ) -> Box> { // create the structure for common entities if required @@ -715,7 +715,7 @@ impl EdgeDisplay { let mut accumulator = String::new(); for b in &self.base { let f = b - .match_edge_display(Rc::clone(&translator), common.clone()); + .match_edge_display(Arc::clone(&translator), common.clone()); accumulator.push_str(&(f)(i, n)); } accumulator @@ -724,7 +724,7 @@ impl EdgeDisplay { pub fn generate_positive<'a>( self, - translator: Rc, + translator: Arc, current_graph: &PositiveSystemGraph, ) -> Box> { // create the structure for common entities if required @@ -764,7 +764,7 @@ impl EdgeDisplay { let mut accumulator = String::new(); for b in &self.base { let f = b.positive_match_edge_display( - Rc::clone(&translator), + Arc::clone(&translator), common.clone(), ); accumulator.push_str(&(f)(i, n)); @@ -856,17 +856,17 @@ impl NodeColorConditional { fn match_node_color_conditional<'a>( &self, color: &'a String, - original_graph: Rc, + original_graph: Arc, star: Option, ) -> Box> { use super::format_helpers::node_formatter::*; match self { | Self::ContextConditional(ContextColorConditional::Nill) => - format_nill(Rc::clone(&original_graph), color.to_string(), star), + format_nill(Arc::clone(&original_graph), color.to_string(), star), | Self::ContextConditional( ContextColorConditional::RecursiveIdentifier(s), ) => format_recursive_identifier( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, *s, @@ -875,7 +875,7 @@ impl NodeColorConditional { ot, set, )) => format_entity_set( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, *ot, @@ -884,25 +884,25 @@ impl NodeColorConditional { | Self::ContextConditional( ContextColorConditional::NonDeterministicChoice, ) => format_non_deterministic_choice( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, ), | Self::ContextConditional(ContextColorConditional::Summation) => format_summation( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, ), | Self::ContextConditional(ContextColorConditional::WaitEntity) => format_wait_entity( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, ), | Self::EntitiesConditional(ot, set) => format_entities_conditional( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, *ot, @@ -914,17 +914,17 @@ impl NodeColorConditional { fn match_positive_node_color_conditional<'a>( &self, color: &'a String, - original_graph: Rc, + original_graph: Arc, star: Option, ) -> Box> { use super::format_helpers::positive_node_formatter::*; match self { | Self::ContextConditional(ContextColorConditional::Nill) => - format_nill(Rc::clone(&original_graph), color.to_string(), star), + format_nill(Arc::clone(&original_graph), color.to_string(), star), | Self::ContextConditional( ContextColorConditional::RecursiveIdentifier(s), ) => format_recursive_identifier( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, *s, @@ -933,7 +933,7 @@ impl NodeColorConditional { ot, set, )) => format_entity_set( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, *ot, @@ -942,25 +942,25 @@ impl NodeColorConditional { | Self::ContextConditional( ContextColorConditional::NonDeterministicChoice, ) => format_non_deterministic_choice( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, ), | Self::ContextConditional(ContextColorConditional::Summation) => format_summation( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, ), | Self::ContextConditional(ContextColorConditional::WaitEntity) => format_wait_entity( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, ), | Self::EntitiesConditional(ot, set) => format_entities_conditional( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), star, *ot, @@ -973,14 +973,14 @@ impl NodeColorConditional { impl NodeColor { pub fn generate<'a>( self, - original_graph: Rc, + original_graph: Arc, star: Option, ) -> Box> { Box::new(move |i, n| { for (rule, color) in &self.conditionals { let f = rule.match_node_color_conditional( color, - Rc::clone(&original_graph), + Arc::clone(&original_graph), star, ); @@ -994,14 +994,14 @@ impl NodeColor { pub fn generate_positive<'a>( self, - original_graph: Rc, + original_graph: Arc, star: Option, ) -> Box> { Box::new(move |i, n| { for (rule, color) in &self.conditionals { let f = rule.match_positive_node_color_conditional( color, - Rc::clone(&original_graph), + Arc::clone(&original_graph), star, ); @@ -1053,54 +1053,54 @@ impl EdgeColorConditional { fn match_edge_color_conditional<'a>( &'a self, color: &'a String, - original_graph: Rc, + original_graph: Arc, ) -> Box> { use super::format_helpers::edge_formatter::*; match self { | Self::Entities(ot, set) => format_entities( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Context(ot, set) => format_context( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::T(ot, set) => format_t( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Reactants(ot, set) => format_reactants( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::ReactantsAbsent(ot, set) => format_reactants_absent( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Inhibitors(ot, set) => format_inhibitors( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::InhibitorsPresent(ot, set) => format_inhibitors_present( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Products(ot, set) => format_products( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), @@ -1111,55 +1111,55 @@ impl EdgeColorConditional { fn match_positive_edge_color_conditional<'a>( &'a self, color: &'a String, - original_graph: Rc, + original_graph: Arc, ) -> Box> { use super::format_helpers::positive_edge_formatter::*; match self { | Self::Entities(ot, set) => format_entities( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Context(ot, set) => format_context( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::T(ot, set) => format_t( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Reactants(ot, set) => format_reactants( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::ReactantsAbsent(ot, set) => format_reactants_absent( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Inhibitors(ot, set) => format_inhibitors( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::InhibitorsPresent(ot, set) => format_inhibitors_present( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), ), | Self::Products(ot, set) => format_products( - Rc::clone(&original_graph), + Arc::clone(&original_graph), color.to_string(), *ot, set.clone(), @@ -1171,13 +1171,13 @@ impl EdgeColorConditional { impl EdgeColor { pub fn generate<'a>( self, - original_graph: Rc, + original_graph: Arc, ) -> Box> { Box::new(move |i, n| { for (rule, color) in &self.conditionals { let f = rule.match_edge_color_conditional( color, - Rc::clone(&original_graph), + Arc::clone(&original_graph), ); if let Some(s) = (f)(i, n) { @@ -1190,13 +1190,13 @@ impl EdgeColor { pub fn generate_positive<'a>( self, - original_graph: Rc, + original_graph: Arc, ) -> Box> { Box::new(move |i, n| { for (rule, color) in &self.conditionals { let f = rule.match_positive_edge_color_conditional( color, - Rc::clone(&original_graph), + Arc::clone(&original_graph), ); if let Some(s) = (f)(i, n) { diff --git a/rsprocess/src/process.rs b/rsprocess/src/process.rs index 7278756..fa099ba 100644 --- a/rsprocess/src/process.rs +++ b/rsprocess/src/process.rs @@ -1,7 +1,7 @@ use std::collections::VecDeque; use std::fmt::Debug; use std::hash::Hash; -use std::rc::Rc; +use std::sync::Arc; use serde::{Deserialize, Serialize}; @@ -40,22 +40,22 @@ pub enum Process { }, EntitySet { entities: Set, - next_process: Rc, + next_process: Arc, }, Guarded { reaction: Reaction, - next_process: Rc, + next_process: Arc, }, WaitEntity { repeat: i64, - repeated_process: Rc, - next_process: Rc, + repeated_process: Arc, + next_process: Arc, }, Summation { - children: Vec>, + children: Vec>, }, NondeterministicChoice { - children: Vec>, + children: Vec>, }, } @@ -74,13 +74,13 @@ impl BasicProcess for Process { | (Self::NondeterministicChoice { children }, new) | (new, Self::NondeterministicChoice { children }) => { let mut new_children = children.clone(); - new_children.push(Rc::new(new.clone())); + new_children.push(Arc::new(new.clone())); Self::NondeterministicChoice { children: new_children, } }, | (_, _) => Self::NondeterministicChoice { - children: vec![Rc::new(self.clone()), Rc::new(new.clone())], + children: vec![Arc::new(self.clone()), Arc::new(new.clone())], }, } } @@ -255,22 +255,22 @@ pub enum PositiveProcess { }, EntitySet { entities: PositiveSet, - next_process: Rc, + next_process: Arc, }, Guarded { reaction: PositiveReaction, - next_process: Rc, + next_process: Arc, }, WaitEntity { repeat: i64, - repeated_process: Rc, - next_process: Rc, + repeated_process: Arc, + next_process: Arc, }, Summation { - children: Vec>, + children: Vec>, }, NondeterministicChoice { - children: Vec>, + children: Vec>, }, } @@ -289,13 +289,13 @@ impl BasicProcess for PositiveProcess { | (Self::NondeterministicChoice { children }, new) | (new, Self::NondeterministicChoice { children }) => { let mut new_children = children.clone(); - new_children.push(Rc::new(new.clone())); + new_children.push(Arc::new(new.clone())); Self::NondeterministicChoice { children: new_children, } }, | (_, _) => Self::NondeterministicChoice { - children: vec![Rc::new(self.clone()), Rc::new(new.clone())], + children: vec![Arc::new(self.clone()), Arc::new(new.clone())], }, } } @@ -467,7 +467,7 @@ impl From<&Process> for PositiveProcess { next_process, } => Self::EntitySet { entities: entities.to_positive_set(IdState::Positive), - next_process: Rc::new((&**next_process).into()), + next_process: Arc::new((&**next_process).into()), }, | Process::RecursiveIdentifier { identifier } => Self::RecursiveIdentifier { @@ -492,7 +492,7 @@ impl From<&Process> for PositiveProcess { .products .to_positive_set(IdState::Positive), }, - next_process: Rc::new((&**next_process).into()), + next_process: Arc::new((&**next_process).into()), }, | Process::WaitEntity { repeat, @@ -500,20 +500,20 @@ impl From<&Process> for PositiveProcess { next_process, } => Self::WaitEntity { repeat: *repeat, - repeated_process: Rc::new((&**repeated_process).into()), - next_process: Rc::new((&**next_process).into()), + repeated_process: Arc::new((&**repeated_process).into()), + next_process: Arc::new((&**next_process).into()), }, | Process::Summation { children } => Self::Summation { children: children .iter() - .map(|c| Rc::new((&**c).into())) + .map(|c| Arc::new((&**c).into())) .collect(), }, | Process::NondeterministicChoice { children } => Self::NondeterministicChoice { children: children .iter() - .map(|c| Rc::new((&**c).into())) + .map(|c| Arc::new((&**c).into())) .collect(), }, } diff --git a/rsprocess/src/reaction.rs b/rsprocess/src/reaction.rs index 255b743..ee1584b 100644 --- a/rsprocess/src/reaction.rs +++ b/rsprocess/src/reaction.rs @@ -316,9 +316,16 @@ impl Reaction { pub fn into_positive_reactions( reactions: &[Self], ) -> Vec { + let reactions = + reactions.iter() + .filter(|r| !r.reactants.is_empty() || !r.inhibitors.is_empty()) + .cloned() + .collect::>(); + let mut res = vec![]; let old_reactions = &reactions; + let all_products = Reaction::all_products(old_reactions); for el in all_products { let p = Reaction::all_reactions_with_product(old_reactions, &el); diff --git a/rsprocess/src/set.rs b/rsprocess/src/set.rs index 8da86d8..77b1a29 100644 --- a/rsprocess/src/set.rs +++ b/rsprocess/src/set.rs @@ -236,6 +236,9 @@ impl Set { reactants: &[Set], inhibitors: &[Set], ) -> Result, String> { + if reactants.is_empty() && inhibitors.is_empty() { + return Ok(vec![]) + } if reactants.len() != inhibitors.len() { return Err(format!( "Different length inputs supplied to create \ @@ -256,6 +259,26 @@ impl Set { r, i )); } + // if we encounter a reaction with no reactants or inhibitors what do we + // do? do we report an error or remove the two sets? here we have + // choosen return an error. + if let Some((r, i)) = reactants + .iter() + .zip(inhibitors.iter()) + .find(|(sr, si)| sr.is_empty() && si.is_empty()) + { + return Err(format!( + "Reaction with no reactants and no inhibitors: \ + reactants: {:?}, inhibitors: {:?}", + r, i + )); + } + // code to instead remove the offending sets: + // let (reactants, inhibitors): (Vec<_>, Vec<_>) = + // reactants.iter() + // .zip(inhibitors.iter()) + // .filter(|(sr, si)| !sr.is_empty() || !si.is_empty()) + // .unzip(); // generate all valid combinations, keeping track of invalid ones (where // one simbol is both positive and negative) diff --git a/rsprocess/src/system.rs b/rsprocess/src/system.rs index 9ab7c65..3f5ccbb 100644 --- a/rsprocess/src/system.rs +++ b/rsprocess/src/system.rs @@ -1,8 +1,7 @@ -use std::cell::RefCell; use std::collections::{HashMap, VecDeque}; use std::fmt::Debug; use std::hash::Hash; -use std::rc::Rc; +use std::sync::{Arc, Mutex}; use petgraph::graph::DiGraph; use serde::{Deserialize, Serialize}; @@ -80,7 +79,7 @@ pub trait ExtensionsSystem: BasicSystem { fn all_transitions(&self) -> Result, String>; - fn run(&self) -> Result>, String>; + fn run(&self) -> Result>, String>; fn digraph(&self) -> Result, String>; @@ -139,10 +138,10 @@ impl ExtensionsSystem for T { } /// see oneRun, run, smartOneRunEK, smartRunEK - fn run(&self) -> Result>, String> { - let mut res = vec![Rc::new(self.clone())]; + fn run(&self) -> Result>, String> { + let mut res = vec![Arc::new(self.clone())]; while let Some((_, next_sys)) = res.last().unwrap().one_transition()? { - res.push(Rc::new(next_sys)); + res.push(Arc::new(next_sys)); } Ok(res) } @@ -273,7 +272,7 @@ impl ExtensionsSystem for T { let mut n = n; let mut res: Vec> = vec![]; let mut current_trace: Trace = Trace::default(); - current_trace.push((None, Rc::new(sys))); + current_trace.push((None, Arc::new(sys))); let mut branch = vec![0]; let mut depth = 0; let mut new_branch = true; @@ -287,13 +286,13 @@ impl ExtensionsSystem for T { if depth >= branch.len() { branch.push(0); current_trace.push(( - Some(Rc::new(current_label)), - Rc::new(next_sys), + Some(Arc::new(current_label)), + Arc::new(next_sys), )); } else { branch[depth] = 0; current_trace[depth] = - (Some(Rc::new(current_label)), Rc::new(next_sys)); + (Some(Arc::new(current_label)), Arc::new(next_sys)); } new_branch = true; } else { @@ -325,10 +324,10 @@ impl ExtensionsSystem for T { ) -> Result, String> { let mut trace = SlicingTrace::default(); - trace.context_elements = Rc::new(self.context_elements()); - trace.products_elements = Rc::new(self.products_elements()); - trace.reactions = Rc::new(self.reactions().clone()); - trace.systems.push(Rc::new(self.clone())); + trace.context_elements = Arc::new(self.context_elements()); + trace.products_elements = Arc::new(self.products_elements()); + trace.reactions = Arc::new(self.reactions().clone()); + trace.systems.push(Arc::new(self.clone())); trace.elements.push(SlicingElement::from(( Self::Set::default(), self.available_entities().clone(), @@ -348,7 +347,7 @@ impl ExtensionsSystem for T { trace .enabled_reactions .push(EnabledReactions::from(enabled_reactions)); - trace.systems.push(Rc::new(current.clone())); + trace.systems.push(Arc::new(current.clone())); loop { let t = current.to_slicing_iterator()?.next(); @@ -360,7 +359,7 @@ impl ExtensionsSystem for T { trace .enabled_reactions .push(EnabledReactions::from(enabled_reactions)); - trace.systems.push(Rc::new(current.clone())); + trace.systems.push(Arc::new(current.clone())); } else { break; } @@ -377,10 +376,10 @@ impl ExtensionsSystem for T { ) -> Result, String> { let mut trace = SlicingTrace::default(); - trace.context_elements = Rc::new(self.context_elements()); - trace.products_elements = Rc::new(self.products_elements()); - trace.reactions = Rc::new(self.reactions().clone()); - trace.systems.push(Rc::new(self.clone())); + trace.context_elements = Arc::new(self.context_elements()); + trace.products_elements = Arc::new(self.products_elements()); + trace.reactions = Arc::new(self.reactions().clone()); + trace.systems.push(Arc::new(self.clone())); trace.elements.push(SlicingElement::from(( Self::Set::default(), self.available_entities().clone(), @@ -400,7 +399,7 @@ impl ExtensionsSystem for T { trace .enabled_reactions .push(EnabledReactions::from(enabled_reactions)); - trace.systems.push(Rc::new(current.clone())); + trace.systems.push(Arc::new(current.clone())); let mut n = limit; loop { @@ -416,7 +415,7 @@ impl ExtensionsSystem for T { trace .enabled_reactions .push(EnabledReactions::from(enabled_reactions)); - trace.systems.push(Rc::new(current.clone())); + trace.systems.push(Arc::new(current.clone())); } else { break; } @@ -541,13 +540,13 @@ where #[derive(Clone, Debug, Deserialize, Serialize)] pub struct System { - pub delta: Rc, + pub delta: Arc, pub available_entities: Set, pub context_process: Process, - pub reaction_rules: Rc>, + pub reaction_rules: Arc>, - context_elements: Rc>>, - products_elements: Rc>>, + context_elements: Arc>>, + products_elements: Arc>>, } impl BasicSystem for System { @@ -589,7 +588,7 @@ impl BasicSystem for System { } fn context_elements(&self) -> Self::Set { - let mut c = self.context_elements.borrow_mut(); + let mut c = self.context_elements.lock().unwrap(); if c.is_some() { c.as_ref().unwrap().clone() } else { @@ -605,7 +604,7 @@ impl BasicSystem for System { } fn products_elements(&self) -> Self::Set { - let mut p = self.products_elements.borrow_mut(); + let mut p = self.products_elements.lock().unwrap(); if p.is_some() { p.as_ref().unwrap().clone() } else { @@ -649,13 +648,13 @@ impl Hash for System { impl Default for System { fn default() -> Self { Self { - delta: Rc::new(Environment::default()), + delta: Arc::new(Environment::default()), available_entities: Set::default(), context_process: Process::Nill, - reaction_rules: Rc::new(Vec::default()), + reaction_rules: Arc::new(Vec::default()), - context_elements: Rc::new(RefCell::new(None)), - products_elements: Rc::new(RefCell::new(None)), + context_elements: Arc::new(Mutex::new(None)), + products_elements: Arc::new(Mutex::new(None)), } } } @@ -688,25 +687,25 @@ impl PrintableWithTranslator for System { impl System { pub fn from( - delta: Rc, + delta: Arc, available_entities: Set, context_process: Process, - reaction_rules: Rc>, + reaction_rules: Arc>, ) -> System { System { - delta: Rc::clone(&delta), + delta: Arc::clone(&delta), available_entities, context_process, - reaction_rules: Rc::clone(&reaction_rules), + reaction_rules: Arc::clone(&reaction_rules), - context_elements: Rc::new(RefCell::new(None)), - products_elements: Rc::new(RefCell::new(None)), + context_elements: Arc::new(Mutex::new(None)), + products_elements: Arc::new(Mutex::new(None)), } } pub fn overwrite_context_elements(&mut self, new_context_elements: Set) { self.context_elements = - Rc::new(RefCell::new(Some(new_context_elements))); + Arc::new(Mutex::new(Some(new_context_elements))); } pub fn overwrite_product_elements(&mut self, new_product_elements: Set) { @@ -714,7 +713,7 @@ impl System { // its computed to ensure consistent behaviour self.context_elements(); self.products_elements = - Rc::new(RefCell::new(Some(new_product_elements))); + Arc::new(Mutex::new(Some(new_product_elements))); } } @@ -861,13 +860,13 @@ impl System { #[derive(Clone, Debug, Deserialize, Serialize)] pub struct PositiveSystem { - pub delta: Rc, + pub delta: Arc, pub available_entities: PositiveSet, pub context_process: PositiveProcess, - pub reaction_rules: Rc>, + pub reaction_rules: Arc>, - context_elements: Rc>>, - products_elements: Rc>>, + context_elements: Arc>>, + products_elements: Arc>>, } impl BasicSystem for PositiveSystem { @@ -910,7 +909,7 @@ impl BasicSystem for PositiveSystem { } fn context_elements(&self) -> Self::Set { - let mut c = self.context_elements.borrow_mut(); + let mut c = self.context_elements.lock().unwrap(); if c.is_some() { c.as_ref().unwrap().clone() } else { @@ -929,7 +928,7 @@ impl BasicSystem for PositiveSystem { } fn products_elements(&self) -> Self::Set { - let mut p = self.products_elements.borrow_mut(); + let mut p = self.products_elements.lock().unwrap(); if p.is_some() { p.as_ref().unwrap().clone() } else { @@ -976,13 +975,13 @@ impl Hash for PositiveSystem { impl Default for PositiveSystem { fn default() -> Self { Self { - delta: Rc::new(PositiveEnvironment::default()), + delta: Arc::new(PositiveEnvironment::default()), available_entities: PositiveSet::default(), context_process: PositiveProcess::default(), - reaction_rules: Rc::new(Vec::default()), + reaction_rules: Arc::new(Vec::default()), - context_elements: Rc::new(RefCell::new(None)), - products_elements: Rc::new(RefCell::new(None)), + context_elements: Arc::new(Mutex::new(None)), + products_elements: Arc::new(Mutex::new(None)), } } } @@ -1020,7 +1019,7 @@ impl From for PositiveSystem { /// all reactions that contains el in the products. /// Should never fail. fn from(value: System) -> Self { - let new_env = Rc::new((&*value.delta).into()); + let new_env = Arc::new((&*value.delta).into()); let positive_entities = value.available_entities.to_positive_set(IdState::Positive); @@ -1042,7 +1041,7 @@ impl From for PositiveSystem { positive_entities.union(&negative_entities); let new_reactions = - Rc::new(PositiveReaction::from_reactions(value.reactions())); + Arc::new(PositiveReaction::from_reactions(value.reactions())); let new_context = value.context_process.into(); Self::from(new_env, new_available_entities, new_context, new_reactions) @@ -1051,19 +1050,19 @@ impl From for PositiveSystem { impl PositiveSystem { pub fn from( - delta: Rc, + delta: Arc, available_entities: PositiveSet, context_process: PositiveProcess, - reaction_rules: Rc>, + reaction_rules: Arc>, ) -> Self { Self { - delta: Rc::clone(&delta), + delta: Arc::clone(&delta), available_entities, context_process, - reaction_rules: Rc::clone(&reaction_rules), + reaction_rules: Arc::clone(&reaction_rules), - context_elements: Rc::new(RefCell::new(None)), - products_elements: Rc::new(RefCell::new(None)), + context_elements: Arc::new(Mutex::new(None)), + products_elements: Arc::new(Mutex::new(None)), } } @@ -1079,7 +1078,7 @@ impl PositiveSystem { new_context_elements: PositiveSet, ) { self.context_elements = - Rc::new(RefCell::new(Some(new_context_elements))); + Arc::new(Mutex::new(Some(new_context_elements))); } pub fn overwrite_product_elements( @@ -1090,6 +1089,6 @@ impl PositiveSystem { // its computed to ensure consistent behaviour self.context_elements(); self.products_elements = - Rc::new(RefCell::new(Some(new_product_elements))); + Arc::new(Mutex::new(Some(new_product_elements))); } } diff --git a/rsprocess/src/system_test.rs b/rsprocess/src/system_test.rs index 0b9ac8a..92ae0a5 100644 --- a/rsprocess/src/system_test.rs +++ b/rsprocess/src/system_test.rs @@ -1,11 +1,10 @@ use super::set::PositiveSet; use super::system::BasicSystem; use crate::system::ExtensionsSystem; +use std::sync::Arc; #[test] fn one_transition() { - use std::rc::Rc; - use super::environment::Environment; use super::process::Process; use super::reaction::Reaction; @@ -13,13 +12,13 @@ fn one_transition() { use super::system::{ExtensionsSystem, System}; let system = System::from( - Rc::new(Environment::default()), + Arc::new(Environment::default()), Set::from([1, 2]), Process::EntitySet { entities: Set::from([]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }, - Rc::new(vec![Reaction::from( + Arc::new(vec![Reaction::from( Set::from([1]), Set::from([3]), Set::from([3]), @@ -41,8 +40,6 @@ fn one_transition() { #[test] fn one_transition_2() { - use std::rc::Rc; - use super::element::{IdState, PositiveType}; use super::environment::PositiveEnvironment; use super::process::PositiveProcess; @@ -51,7 +48,7 @@ fn one_transition_2() { use super::system::{ExtensionsSystem, PositiveSystem}; let system = PositiveSystem::from( - Rc::new(PositiveEnvironment::default()), + Arc::new(PositiveEnvironment::default()), PositiveSet::from([ (1, IdState::Positive), (2, IdState::Positive), @@ -59,13 +56,13 @@ fn one_transition_2() { ]), PositiveProcess::WaitEntity { repeat: 2, - repeated_process: Rc::new(PositiveProcess::EntitySet { + repeated_process: Arc::new(PositiveProcess::EntitySet { entities: PositiveSet::default(), - next_process: Rc::new(PositiveProcess::Nill), + next_process: Arc::new(PositiveProcess::Nill), }), - next_process: Rc::new(PositiveProcess::Nill), + next_process: Arc::new(PositiveProcess::Nill), }, - Rc::new(vec![ + Arc::new(vec![ PositiveReaction { reactants: PositiveSet::from([ (1, IdState::Positive), @@ -119,8 +116,6 @@ fn one_transition_2() { #[test] fn convertion() { - use std::rc::Rc; - use super::environment::Environment; use super::process::Process; use super::reaction::Reaction; @@ -128,13 +123,13 @@ fn convertion() { use super::system::{PositiveSystem, System}; let system = System::from( - Rc::new(Environment::default()), + Arc::new(Environment::default()), Set::from([1, 2]), Process::EntitySet { entities: Set::from([]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }, - Rc::new(vec![Reaction::from( + Arc::new(vec![Reaction::from( Set::from([1]), Set::from([3]), Set::from([3]), @@ -149,8 +144,6 @@ fn convertion() { #[test] fn traces_1() { - use std::rc::Rc; - use super::environment::Environment; use super::process::Process; use super::reaction::Reaction; @@ -158,48 +151,48 @@ fn traces_1() { use super::system::{ExtensionsSystem, System}; let system = System::from( - Rc::new(Environment::from([ + Arc::new(Environment::from([ (100, Process::WaitEntity { repeat: 2, - repeated_process: Rc::new(Process::EntitySet { + repeated_process: Arc::new(Process::EntitySet { entities: Set::from([1]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), (102, Process::WaitEntity { repeat: 3, - repeated_process: Rc::new(Process::EntitySet { + repeated_process: Arc::new(Process::EntitySet { entities: Set::from([2]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), (103, Process::WaitEntity { repeat: 4, - repeated_process: Rc::new(Process::EntitySet { + repeated_process: Arc::new(Process::EntitySet { entities: Set::from([3]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), (101, Process::Summation { children: vec![ - Rc::new(Process::EntitySet { + Arc::new(Process::EntitySet { entities: Set::from([10]), - next_process: Rc::new(Process::RecursiveIdentifier { + next_process: Arc::new(Process::RecursiveIdentifier { identifier: 100, }), }), - Rc::new(Process::EntitySet { + Arc::new(Process::EntitySet { entities: Set::from([11]), - next_process: Rc::new(Process::RecursiveIdentifier { + next_process: Arc::new(Process::RecursiveIdentifier { identifier: 102, }), }), - Rc::new(Process::EntitySet { + Arc::new(Process::EntitySet { entities: Set::from([11]), - next_process: Rc::new(Process::RecursiveIdentifier { + next_process: Arc::new(Process::RecursiveIdentifier { identifier: 103, }), }), @@ -208,7 +201,7 @@ fn traces_1() { ])), Set::from([1, 2]), Process::RecursiveIdentifier { identifier: 101 }, - Rc::new(vec![ + Arc::new(vec![ Reaction::from(Set::from([1]), Set::from([3]), Set::from([3])), Reaction::from(Set::from([3]), Set::from([1]), Set::from([1])), Reaction::from(Set::from([2]), Set::default(), Set::from([4])), @@ -237,8 +230,6 @@ fn traces_1() { #[test] fn traces_empty_env() { - use std::rc::Rc; - use super::environment::Environment; use super::process::Process; use super::reaction::Reaction; @@ -246,17 +237,17 @@ fn traces_empty_env() { use super::system::{ExtensionsSystem, System}; let system = System::from( - Rc::new(Environment::from([])), + Arc::new(Environment::from([])), Set::from([1, 2]), Process::WaitEntity { repeat: 10, - repeated_process: Rc::new(Process::EntitySet { + repeated_process: Arc::new(Process::EntitySet { entities: Set::from([1, 2]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }, - Rc::new(vec![ + Arc::new(vec![ Reaction::from(Set::from([1]), Set::from([3]), Set::from([3])), Reaction::from(Set::from([3]), Set::from([1]), Set::from([1])), Reaction::from(Set::from([2]), Set::default(), Set::from([4])), @@ -270,8 +261,6 @@ fn traces_empty_env() { #[test] fn conversion_reactions() { - use std::rc::Rc; - use super::element::IdState::*; use super::environment::Environment; use super::process::Process; @@ -280,10 +269,10 @@ fn conversion_reactions() { use super::system::{PositiveSystem, System}; let system = System::from( - Rc::new(Environment::from([])), + Arc::new(Environment::from([])), Set::from([1, 2]), Process::Nill, - Rc::new(vec![ + Arc::new(vec![ Reaction::from(Set::from([2]), Set::from([1, 3]), Set::from([5])), Reaction::from(Set::from([1, 2]), Set::from([3]), Set::from([5])), ]), @@ -314,8 +303,6 @@ fn conversion_reactions() { #[test] fn conversion_entities() { - use std::rc::Rc; - use super::element::IdState::*; use super::environment::Environment; use super::process::Process; @@ -324,10 +311,10 @@ fn conversion_entities() { use super::system::{PositiveSystem, System}; let system = System::from( - Rc::new(Environment::from([])), + Arc::new(Environment::from([])), Set::from([1, 2]), Process::Nill, - Rc::new(vec![ + Arc::new(vec![ Reaction::from(Set::from([2]), Set::from([1, 3]), Set::from([5])), Reaction::from(Set::from([1, 2]), Set::from([3]), Set::from([5])), ]), @@ -348,8 +335,6 @@ fn conversion_entities() { #[test] fn slice_trace() { - use std::rc::Rc; - use super::environment::Environment; use super::process::Process; use super::reaction::Reaction; @@ -361,16 +346,16 @@ fn slice_trace() { let mut tr = |a| translator.encode(a); let system = System::from( - Rc::new(Environment::from([])), + Arc::new(Environment::from([])), Set::from([tr("a"), tr("b")]), Process::EntitySet { entities: Set::from([tr("c")]), - next_process: Rc::new(Process::EntitySet { + next_process: Arc::new(Process::EntitySet { entities: Set::from([]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), }, - Rc::new(vec![Reaction::from( + Arc::new(vec![Reaction::from( Set::from([tr("a")]), Set::from([]), Set::from([tr("b")]), @@ -387,8 +372,6 @@ fn slice_trace() { #[test] fn slice_trace_2() { - use std::rc::Rc; - use super::environment::Environment; use super::process::Process; use super::reaction::Reaction; @@ -400,16 +383,16 @@ fn slice_trace_2() { let mut tr = |a| translator.encode(a); let system = System::from( - Rc::new(Environment::from([])), + Arc::new(Environment::from([])), Set::from([tr("a"), tr("b")]), Process::EntitySet { entities: Set::from([tr("c")]), - next_process: Rc::new(Process::EntitySet { + next_process: Arc::new(Process::EntitySet { entities: Set::from([]), - next_process: Rc::new(Process::Nill), + next_process: Arc::new(Process::Nill), }), }, - Rc::new(vec![ + Arc::new(vec![ Reaction::from( Set::from([tr("a")]), Set::from([tr("b")]), diff --git a/rsprocess/src/trace.rs b/rsprocess/src/trace.rs index 47b286d..385eeb3 100644 --- a/rsprocess/src/trace.rs +++ b/rsprocess/src/trace.rs @@ -1,6 +1,6 @@ use std::fmt::Debug; use std::ops::{Index, IndexMut}; -use std::rc::Rc; +use std::sync::Arc; use std::slice::SliceIndex; use serde::{Deserialize, Serialize}; @@ -10,7 +10,7 @@ use crate::set::{BasicSet, PositiveSet, Set}; use crate::system::{BasicSystem, PositiveSystem, System}; use crate::translator::{Formatter, PrintableWithTranslator}; -type TraceElement = (Option>, Rc); +type TraceElement = (Option>, Arc); #[derive(Clone, Default)] pub struct Trace { @@ -197,11 +197,11 @@ pub struct SlicingTrace { pub elements: Vec>, pub enabled_reactions: Vec, - pub reactions: Rc>, - pub systems: Vec>, + pub reactions: Arc>, + pub systems: Vec>, - pub context_elements: Rc, - pub products_elements: Rc, + pub context_elements: Arc, + pub products_elements: Arc, } impl Default for SlicingTrace { @@ -209,10 +209,10 @@ impl Default for SlicingTrace { Self { elements: Vec::default(), enabled_reactions: Vec::default(), - reactions: Rc::new(Vec::default()), + reactions: Arc::new(Vec::default()), systems: Vec::default(), - context_elements: Rc::new(S::default()), - products_elements: Rc::new(S::default()), + context_elements: Arc::new(S::default()), + products_elements: Arc::new(S::default()), } } } @@ -278,10 +278,10 @@ impl SlicingTrace { let new_trace = Self { elements: reversed_elements, enabled_reactions: reversed_enabled_reactions, - reactions: Rc::clone(&self.reactions), + reactions: Arc::clone(&self.reactions), systems: self.systems.to_vec(), - context_elements: Rc::clone(&self.context_elements), - products_elements: Rc::clone(&self.products_elements), + context_elements: Arc::clone(&self.context_elements), + products_elements: Arc::clone(&self.products_elements), }; Ok(new_trace) @@ -340,10 +340,10 @@ impl SlicingTrace { let new_trace = Self { elements: reversed_elements, enabled_reactions: reversed_enabled_reactions, - reactions: Rc::clone(&self.reactions), + reactions: Arc::clone(&self.reactions), systems: self.systems.to_vec(), - context_elements: Rc::clone(&self.context_elements), - products_elements: Rc::clone(&self.products_elements), + context_elements: Arc::clone(&self.context_elements), + products_elements: Arc::clone(&self.products_elements), }; Ok(new_trace) diff --git a/rsprocess/src/trace_test.rs b/rsprocess/src/trace_test.rs index 8b70034..8819864 100644 --- a/rsprocess/src/trace_test.rs +++ b/rsprocess/src/trace_test.rs @@ -1,4 +1,4 @@ -use std::rc::Rc; +use std::sync::Arc; use crate::element::IdState; use crate::reaction::{BasicReaction, PositiveReaction, Reaction}; @@ -95,10 +95,10 @@ fn slice_atoi() { elements, enabled_reactions, - reactions: Rc::new(reactions), + reactions: Arc::new(reactions), systems: vec![], - context_elements: Rc::new(context_elements), - products_elements: Rc::new(products_elements), + context_elements: Arc::new(context_elements), + products_elements: Arc::new(products_elements), }; let marking = ["tbet"] @@ -199,15 +199,15 @@ fn slice_positive_atoi() { .collect::>(); let system = System::from( - Rc::new(crate::environment::Environment::from([])), + Arc::new(crate::environment::Environment::from([])), Set::from([]), crate::process::Process::Nill, - Rc::new(reactions), + Arc::new(reactions), ); let converted_system: PositiveSystem = system.into(); let mut reactions = - Rc::try_unwrap(converted_system.reaction_rules).unwrap(); + Arc::try_unwrap(converted_system.reaction_rules).unwrap(); reactions.sort_by(|a, b| { a.reactants .cmp(&b.reactants) @@ -365,10 +365,10 @@ fn slice_positive_atoi() { elements, enabled_reactions, - reactions: Rc::new(reactions), + reactions: Arc::new(reactions), systems: vec![], - context_elements: Rc::new(context_elements), - products_elements: Rc::new(products_elements), + context_elements: Arc::new(context_elements), + products_elements: Arc::new(products_elements), }; let marking = Into::::into( diff --git a/rsprocess/src/transitions.rs b/rsprocess/src/transitions.rs index c305e47..d838b91 100644 --- a/rsprocess/src/transitions.rs +++ b/rsprocess/src/transitions.rs @@ -1,7 +1,7 @@ //! Module for helper structure for simulation use std::fmt::Debug; -use std::rc::Rc; +use std::sync::Arc; use super::label::{Label, PositiveLabel}; use super::process::{BasicProcess, PositiveProcess, Process}; @@ -22,7 +22,7 @@ pub struct TransitionsIterator< Sys: BasicSystem, Proc: BasicProcess, > { - choices_iterator: std::vec::IntoIter<(Rc, Rc)>, + choices_iterator: std::vec::IntoIter<(Arc, Arc)>, system: &'a Sys, } @@ -95,10 +95,10 @@ impl<'a> Iterator for TransitionsIterator<'a, Set, System, Process> { products.clone(), ); let new_system = System::from( - Rc::clone(&self.system.delta), + Arc::clone(&self.system.delta), products, (*k).clone(), - Rc::clone(&self.system.reaction_rules), + Arc::clone(&self.system.reaction_rules), ); Some((label, new_system)) } @@ -186,11 +186,11 @@ impl<'a> Iterator products.clone(), ); let new_system = PositiveSystem::from( - Rc::clone(&self.system.delta), + Arc::clone(&self.system.delta), // products.add_unique(&self.system.negated_products_elements()), products, (*k).clone(), - Rc::clone(&self.system.reaction_rules), + Arc::clone(&self.system.reaction_rules), ); Some((label, new_system)) } @@ -261,12 +261,12 @@ impl<'a> Iterator for TraceIterator<'a, Set, System, Process> { ); let new_system = System::from( - Rc::clone(&self.system.delta), + Arc::clone(&self.system.delta), // all_products.add_unique(&self.system. // negated_products_elements()), all_products.clone(), (*k).clone(), - Rc::clone(&self.system.reaction_rules), + Arc::clone(&self.system.reaction_rules), ); Some(( @@ -302,12 +302,12 @@ impl<'a> Iterator ); let new_system = PositiveSystem::from( - Rc::clone(&self.system.delta), + Arc::clone(&self.system.delta), // all_products.add_unique(&self.system. // negated_products_elements()), all_products.clone(), (*k).clone(), - Rc::clone(&self.system.reaction_rules), + Arc::clone(&self.system.reaction_rules), ); Some((