From 1e885fa95b1282a92ef3291276a5b8e5c5331dc7 2020-02-04 14:41:54 From: Christopher Esterhuyse Date: 2020-02-04 14:41:54 Subject: [PATCH] more debug prints on branch predicates --- diff --git a/Cargo.toml b/Cargo.toml index d0e004afbc8ddd1f0254255ceffc108d4978bf6a..abb6d63606baaafe792850aa1913cbd3f59f529b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,19 @@ [package] name = "reowolf_rs" version = "0.1.0" -authors = ["Christopher Esterhuyse ", "Hans-Dieter Hiep "] +authors = [ + "Christopher Esterhuyse ", + "Hans-Dieter Hiep " +] edition = "2018" [dependencies] +# runtime stuff getrandom = "0.1.14" # tiny crate. used to guess controller-id take_mut = "0.2.2" maplit = "1.0.2" # convenience macros -indexmap = "1.3.0" # hashsets with efficient arbitrary element removal +indexmap = "1.3.0" # hashsets/hashmaps with efficient arbitrary element removal # network stuff integer-encoding = "1.0.7" @@ -29,4 +33,4 @@ crate-type = ["cdylib"] [features] default = ["ffi"] -ffi = [] \ No newline at end of file +ffi = [] # no feature dependencies \ No newline at end of file diff --git a/src/macros.rs b/src/macros.rs index 7935e81f341f844fe743ee3467a37ddc51b97033..a478fd71784f5fe69cbb42f8bf141b388868a5fc 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -1,3 +1,10 @@ +macro_rules! lockprintln { + () => (print!("\n")); + ($($arg:tt)*) => ({ + use std::io::Write; + std::writeln!(std::io::stdout().lock(), $($arg)*).expect("LPRINTLN"); + }) +} macro_rules! assert_let { ($pat:pat = $expr:expr => $work:expr) => { if let $pat = $expr { diff --git a/src/runtime/actors.rs b/src/runtime/actors.rs index ed3c75146dcbd158ade0e1044c0438d372bfab38..86aa3c4c3d1cf33c7a78ac5224b83a4ff0ed58b6 100644 --- a/src/runtime/actors.rs +++ b/src/runtime/actors.rs @@ -141,14 +141,31 @@ impl PolyP { payload: Payload, ) -> Result { // try exact match + let cid = m_ctx.inner.channel_id_stream.controller_id; + let to_run = if self.complete.contains_key(&payload_predicate) { // exact match with stopped machine + + lockprintln!( + "{:?}: ... poly_recv_run matched stopped machine exactly! nothing to do here", + cid, + ); vec![] } else if let Some(mut branch) = self.incomplete.remove(&payload_predicate) { // exact match with running machine + + lockprintln!( + "{:?}: ... poly_recv_run matched running machine exactly! pred is {:?}", + cid, + &payload_predicate + ); branch.inbox.insert(ekey, payload); vec![(payload_predicate, branch)] } else { + lockprintln!( + "{:?}: ... poly_recv_run didn't have any exact matches... Let's try feed it to all branches", + cid, + ); let mut incomplete2 = HashMap::<_, _>::default(); let to_run = self .incomplete @@ -157,12 +174,25 @@ impl PolyP { use CommonSatResult as Csr; match old_predicate.common_satisfier(&payload_predicate) { Csr::FormerNotLatter | Csr::Equivalent => { + lockprintln!( + "{:?}: ... poly_recv_run This branch is compatible unaltered! branch pred: {:?}", + cid, + &old_predicate + ); // old_predicate COVERS the assumptions of payload_predicate let was = branch.inbox.insert(ekey, payload.clone()); assert!(was.is_none()); // INBOX MUST BE EMPTY! Some((old_predicate, branch)) } - Csr::New(unified) => { + Csr::New(new) => { + + lockprintln!( + "{:?}: ... poly_recv_run payloadpred {:?} and branchpred {:?} satisfied by new pred {:?}. FORKING", + cid, + &old_predicate, + &payload_predicate, + &new, + ); // payload_predicate has new assumptions. FORK! let mut payload_branch = branch.clone(); let was = payload_branch.inbox.insert(ekey, payload.clone()); @@ -170,9 +200,16 @@ impl PolyP { // put the original back untouched incomplete2.insert(old_predicate, branch); - Some((unified, payload_branch)) + Some((new, payload_branch)) } Csr::LatterNotFormer => { + + lockprintln!( + "{:?}: ... poly_recv_run payloadpred {:?} subsumes branch pred {:?}. FORKING", + cid, + &old_predicate, + &payload_predicate, + ); // payload_predicate has new assumptions. FORK! let mut payload_branch = branch.clone(); let was = payload_branch.inbox.insert(ekey, payload.clone()); @@ -183,6 +220,12 @@ impl PolyP { Some((payload_predicate.clone(), payload_branch)) } Csr::Nonexistant => { + lockprintln!( + "{:?}: ... poly_recv_run SKIPPING because branchpred={:?}. payloadpred={:?}", + cid, + &old_predicate, + &payload_predicate, + ); // predicates contradict incomplete2.insert(old_predicate, branch); None @@ -193,6 +236,7 @@ impl PolyP { std::mem::swap(&mut self.incomplete, &mut incomplete2); to_run }; + lockprintln!("{:?}: ... DONE FEEDING BRANCHES. {} branches to run!", cid, to_run.len(),); self.poly_run_these_branches(m_ctx, protocol_description, to_run) } diff --git a/src/runtime/communication.rs b/src/runtime/communication.rs index 1c0749e848722b157d134d84e1ac6713b79813ea..8df9f261e33c9ae5c9929f5bdcc78c727ccb182e 100644 --- a/src/runtime/communication.rs +++ b/src/runtime/communication.rs @@ -1,14 +1,6 @@ use crate::common::*; use crate::runtime::{actors::*, endpoint::*, errors::*, *}; -macro_rules! lockprintln { - () => (print!("\n")); - ($($arg:tt)*) => ({ - use std::io::Write; - std::writeln!(std::io::stdout().lock(), $($arg)*).expect("LPRINTLN"); - }) -} - impl Controller { fn end_round_with_decision(&mut self, decision: Predicate) -> Result<(), SyncErr> { let mut all_inboxes = HashMap::default(); diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 5dbac51a7f84823a0de49e6b4521231d187e60f6..50d90e104bbd3c55fa4892c62290a386147f65fa 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -438,7 +438,13 @@ impl Predicate { impl Debug for Predicate { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { for (ChannelId { controller_id, channel_index }, &v) in self.assigned.iter() { - write!(f, "{:?}=>{}", (controller_id, channel_index), if v { 'T' } else { 'F' })?; + write!( + f, + "({:?},{:?})=>{}, ", + controller_id, + channel_index, + if v { 'T' } else { 'F' } + )?; } Ok(()) }