diff --git a/Cargo.lock b/Cargo.lock index 41c5b75b94a4..b64d7d666785 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -143,9 +143,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.86" +version = "1.0.89" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +checksum = "86fdf8605db99b54d3cd748a44c6d04df638eb5dafb219b135d0149bd0db01f6" dependencies = [ "backtrace", ] @@ -497,9 +497,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.14" +version = "1.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d2eb3cd3d1bf4529e31c215ee6f93ec5a3d536d9f578f93d9d33ee19562932" +checksum = "2e80e3b6a3ab07840e1cae9b0666a63970dc28e8ed5ffbcdacbfc760c281bfc1" dependencies = [ "shlex", ] @@ -1339,6 +1339,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" + [[package]] name = "headers" version = "0.3.9" @@ -1563,7 +1569,7 @@ dependencies = [ "rand_distr", "ref-cast", "regex", - "rustc-hash", + "rustc-hash 1.1.0", "sealed", "serde", "serde_json", @@ -1781,12 +1787,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.4.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" +checksum = "707907fe3c25f5424cce2cb7e1cbcafee6bdbe735ca90ef77c29e84591e5b9da" dependencies = [ "equivalent", - "hashbrown 0.14.5", + "hashbrown 0.15.0", ] [[package]] @@ -1972,9 +1978,12 @@ version = "0.5.7" dependencies = [ "cc-traits", "lattices_macro", + "ref-cast", "sealed", "serde", "trybuild", + "variadics", + "variadics_macro", ] [[package]] @@ -2679,9 +2688,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.88" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "7c3a7fc5db1e57d5a779a352c8cdb57b29aa4c40cc69c3a68a7fedc815fbf2f9" dependencies = [ "unicode-ident", ] @@ -3066,9 +3075,9 @@ dependencies = [ [[package]] name = "rust-sitter" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f69b9a5d53b74db5166799a0024c2849e144c652dd6253c5bf58dfe086798cbc" +checksum = "890cd29b9cd344678003f03f22d8b171a4d4b333f1ba88e2804b1ef7dd39b1d5" dependencies = [ "rust-sitter-macro", "tree-sitter-c2rust", @@ -3076,41 +3085,41 @@ dependencies = [ [[package]] name = "rust-sitter-common" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b559ebfd4114d398a36dfe25d7221bf84839fc3ef1309a6b7f4d1eece78dc690" +checksum = "3d8e1c8d26b8d5fb23415a5123588669e776ad934abbfbe6d8677ed322694216" dependencies = [ "quote", - "syn 1.0.109", + "syn 2.0.75", ] [[package]] name = "rust-sitter-macro" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8238447de92f7104ddbda8b5fd38a9be055229373283ef42b774b340d8117def" +checksum = "07defe73314513d2b671b4c81603a236193eabe8ec7afd480dd3ed769dd75fb6" dependencies = [ "proc-macro2", "quote", "rust-sitter-common", - "syn 1.0.109", + "syn 2.0.75", ] [[package]] name = "rust-sitter-tool" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b840052f42d08fb67d13f68b72f1c41f99865d83239f4edff8fa1c6fd6fa0a12" +checksum = "9e666bbe8cf47a6ba0c88da4f2b98ebadb98bc1b5b9723aa5784137ae93f9436" dependencies = [ "cc", "rust-sitter-common", "serde", "serde_json", - "syn 1.0.109", - "syn-inline-mod 0.5.0", + "syn 2.0.75", + "syn-inline-mod", "tempfile", "tree-sitter", - "tree-sitter-cli", + "tree-sitter-generate", ] [[package]] @@ -3125,6 +3134,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc-hash" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "583034fd73374156e66797ed8e5b0d5690409c9226b22d87cb7f19821c05d152" + [[package]] name = "rustc_version" version = "0.2.3" @@ -3218,9 +3233,9 @@ checksum = "5a9f47faea3cad316faa914d013d24f471cd90bfca1a0c70f05a3f42c6441e99" [[package]] name = "serde" -version = "1.0.208" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] @@ -3238,9 +3253,9 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.208" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", @@ -3249,9 +3264,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.127" +version = "1.0.128" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8043c06d9f82bd7271361ed64f415fe5e12a77fdb52e573e7f06a516dea329ad" +checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" dependencies = [ "indexmap", "itoa", @@ -3469,7 +3484,7 @@ dependencies = [ "quote", "sha256", "syn 2.0.75", - "syn-inline-mod 0.6.0", + "syn-inline-mod", ] [[package]] @@ -3494,6 +3509,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" +[[package]] +name = "streaming-iterator" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" + [[package]] name = "strsim" version = "0.11.1" @@ -3522,16 +3543,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "syn-inline-mod" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b670f535364c67358ecffb60b9f2579f9b45d3c71e8cca6d45d22ee0fadaa7eb" -dependencies = [ - "proc-macro2", - "syn 1.0.109", -] - [[package]] name = "syn-inline-mod" version = "0.6.0" @@ -3942,123 +3953,59 @@ dependencies = [ [[package]] name = "tree-sitter" -version = "0.22.6" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df7cc499ceadd4dcdf7ec6d4cbc34ece92c3fa07821e287aedecd4416c516dca" +checksum = "f9871f16d6cf5c4757dcf30d5d2172a2df6987c510c017bbb7abfb7f9aa24d06" dependencies = [ "cc", "regex", + "regex-syntax 0.8.4", + "streaming-iterator", + "tree-sitter-language", ] [[package]] name = "tree-sitter-c2rust" -version = "0.22.6" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62cd4f1075a82f3c4ae5e93dc39d4e0765d132a6d2773b3d86214fcc54e6d1e9" +checksum = "a5f97c8ed19295f92e02af90c915c72d0836e08132f155709bc45b66acdfde35" dependencies = [ "c2rust-bitfields", "once_cell", "regex", + "regex-syntax 0.8.4", + "streaming-iterator", + "tree-sitter-language", ] [[package]] -name = "tree-sitter-cli" -version = "0.22.6" +name = "tree-sitter-generate" +version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7437ac48e37e5014007527ed9281c00c333c9ad0731e1c8489c0eff667b99d5" +checksum = "169563a4e3713ad23a2a755446ed1e3af7db5cfc3b8beb0986b7e96f3619aec3" dependencies = [ - "ansi_term", - "anstyle", "anyhow", - "clap", - "ctrlc", - "difference", - "dirs", - "filetime", - "glob", "heck 0.5.0", - "html-escape", "indexmap", "indoc", "lazy_static", "log", - "memchr", "regex", "regex-syntax 0.8.4", - "rustc-hash", + "rustc-hash 2.0.0", "semver 1.0.23", "serde", - "serde_derive", "serde_json", "smallbitvec", - "tiny_http", - "tree-sitter", - "tree-sitter-config", - "tree-sitter-highlight", - "tree-sitter-loader", - "tree-sitter-tags", - "walkdir", - "wasmparser", - "webbrowser", -] - -[[package]] -name = "tree-sitter-config" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d64b4608a1d822f56e3afcecabfa4915a768ea92bc44abad1ae32cd4c607ebd" -dependencies = [ - "anyhow", - "dirs", - "serde", - "serde_json", -] - -[[package]] -name = "tree-sitter-highlight" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eaca0fe34fa96eec6aaa8e63308dbe1bafe65a6317487c287f93938959b21907" -dependencies = [ - "lazy_static", - "regex", - "thiserror", "tree-sitter", + "url", ] [[package]] -name = "tree-sitter-loader" -version = "0.22.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c9b13749644fbe22ec25c79861dc1e637ef4ab9e469fd820fcb30b10091293" -dependencies = [ - "anyhow", - "cc", - "dirs", - "fs4", - "indoc", - "libloading", - "once_cell", - "regex", - "serde", - "serde_json", - "tempfile", - "tree-sitter", - "tree-sitter-highlight", - "tree-sitter-tags", -] - -[[package]] -name = "tree-sitter-tags" -version = "0.22.6" +name = "tree-sitter-language" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34380416097ab36d1b4cd83f887d9e150ea4feaeb6ee9a5ecfe53d26839acc69" -dependencies = [ - "memchr", - "regex", - "thiserror", - "tree-sitter", -] +checksum = "e8ddffe35a0e5eeeadf13ff7350af564c6e73993a24db62caee1822b185c2600" [[package]] name = "try-lock" @@ -4227,6 +4174,7 @@ dependencies = [ "form_urlencoded", "idna", "percent-encoding", + "serde", ] [[package]] @@ -4271,6 +4219,19 @@ dependencies = [ "trybuild", ] +[[package]] +name = "variadics_macro" +version = "0.5.5" +dependencies = [ + "insta", + "prettyplease", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.75", + "variadics", +] + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 5c8d628cbb2b..ab8fef76bc85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -29,6 +29,7 @@ members = [ "stageleft_tool", "topolotree", "variadics", + "variadics_macro", "website_playground", ] diff --git a/docs/docs/hydroflow_plus/clusters.mdx b/docs/docs/hydroflow_plus/clusters.mdx index 63380857ca5b..5d742324c673 100644 --- a/docs/docs/hydroflow_plus/clusters.mdx +++ b/docs/docs/hydroflow_plus/clusters.mdx @@ -32,7 +32,7 @@ stream.for_each(q!(|x| println!("{}", x))) ## Sending Data Because clusters represent a set of instances, adding networking requires us to specify _which_ instance(s) to send data to. Clusters provide different types depending on if the source or receiver is a cluster or a process. -Elements in a cluster are identified by a **cluster ID** (a `u32`). To get the IDs of all instances in a cluster, use the `ids` method on cluster, which returns a runtime expression of type `&Vec` (which can only be used inside `q!()` or as an argument to `source_iter`). All IDs always are ranging from 0 through the length of the IDs vector. +Elements in a cluster are identified by a **cluster ID** (a `ClusterId` where `C` is the typetag of the cluster). To get the IDs of all instances in a cluster, use the `members` method on cluster, which returns a runtime expression of type `&Vec>` (which can only be used inside `q!()` or as an argument to `source_iter`). All IDs always are ranging from 0 through the length of the IDs vector. This can then be passed into `source_iter` to load the IDs into the graph. ```rust @@ -40,7 +40,7 @@ let stream = process.source_iter(cluster.members()).cloned(); ``` ### One-to-Many -When sending data from a process to a cluster, the source must be a stream of tuples of the form `(u32, T)` and sends each `T` element to the instance with the matching `u32` ID. +When sending data from a process to a cluster, the source must be a stream of tuples of the form `(ClusterId<_>, T)` and sends each `T` element to the instance with the matching ID. This is useful for partitioning data across instances. For example, we can partition a stream of elements in a round-robin fashion by using `enumerate` to add a sequence number to each element, then using `send_bincode` to send each element to the instance with the matching sequence number: ```rust @@ -48,7 +48,7 @@ let cluster_ids = cluster.members(); let stream = process.source_iter(q!(vec![123, 456, 789])) .enumerate() .map(q!(|(i, x)| ( - i % cluster_ids.len() as u32, + ClusterId::from_raw(i % cluster_ids.len() as u32), x ))) .send_bincode(&cluster); diff --git a/hydroflow/src/compiled/pull/anti_join.rs b/hydroflow/src/compiled/pull/anti_join.rs index 9e11f691f1c1..97421b7de62d 100644 --- a/hydroflow/src/compiled/pull/anti_join.rs +++ b/hydroflow/src/compiled/pull/anti_join.rs @@ -12,7 +12,7 @@ where pos_state: &'a mut FxHashSet<(Key, V)>, } -impl<'a, Key, V, Ipos> Iterator for AntiJoin<'a, Key, V, Ipos> +impl Iterator for AntiJoin<'_, Key, V, Ipos> where Key: Eq + std::hash::Hash + Clone, V: Eq + std::hash::Hash + Clone, diff --git a/hydroflow/src/compiled/pull/cross_join.rs b/hydroflow/src/compiled/pull/cross_join.rs index 90f743d9bc92..6b9629fa65f9 100644 --- a/hydroflow/src/compiled/pull/cross_join.rs +++ b/hydroflow/src/compiled/pull/cross_join.rs @@ -30,7 +30,7 @@ where state: &'a mut CrossJoinState, } -impl<'a, I1, V1: 'static, I2, V2: 'static> Iterator for CrossJoin<'a, I1, V1, I2, V2> +impl Iterator for CrossJoin<'_, I1, V1, I2, V2> where V1: Eq + Clone, V2: Eq + Clone, diff --git a/hydroflow/src/compiled/pull/symmetric_hash_join.rs b/hydroflow/src/compiled/pull/symmetric_hash_join.rs index d240e6a347ad..1665c9940a05 100644 --- a/hydroflow/src/compiled/pull/symmetric_hash_join.rs +++ b/hydroflow/src/compiled/pull/symmetric_hash_join.rs @@ -18,8 +18,8 @@ where rhs_state: &'a mut RhsState, } -impl<'a, Key, I1, V1, I2, V2, LhsState, RhsState> Iterator - for SymmetricHashJoin<'a, Key, I1, V1, I2, V2, LhsState, RhsState> +impl Iterator + for SymmetricHashJoin<'_, Key, I1, V1, I2, V2, LhsState, RhsState> where Key: Eq + std::hash::Hash + Clone, V1: Clone, diff --git a/hydroflow/src/scheduled/graph.rs b/hydroflow/src/scheduled/graph.rs index 85d71d98bfe0..2d4e96962ee2 100644 --- a/hydroflow/src/scheduled/graph.rs +++ b/hydroflow/src/scheduled/graph.rs @@ -47,7 +47,7 @@ pub struct Hydroflow<'a> { /// See [`Self::diagnostics()`]. diagnostics: Option>>, } -impl<'a> Default for Hydroflow<'a> { +impl Default for Hydroflow<'_> { fn default() -> Self { let stratum_queues = vec![Default::default()]; // Always initialize stratum #0. let (event_queue_send, event_queue_recv) = mpsc::unbounded_channel(); @@ -69,7 +69,7 @@ impl<'a> Default for Hydroflow<'a> { } /// Methods for [`TeeingHandoff`] teeing and dropping. -impl<'a> Hydroflow<'a> { +impl Hydroflow<'_> { /// Tees a [`TeeingHandoff`]. pub fn teeing_handoff_tee( &mut self, @@ -794,7 +794,7 @@ impl<'a> Hydroflow<'a> { } } -impl<'a> Hydroflow<'a> { +impl Hydroflow<'_> { /// Alias for [`Context::request_task`]. pub fn request_task(&mut self, future: Fut) where @@ -814,7 +814,7 @@ impl<'a> Hydroflow<'a> { } } -impl<'a> Drop for Hydroflow<'a> { +impl Drop for Hydroflow<'_> { fn drop(&mut self) { self.abort_tasks(); } diff --git a/hydroflow/src/scheduled/graph_ext.rs b/hydroflow/src/scheduled/graph_ext.rs index 6f54413d832e..1d0be9d28dd6 100644 --- a/hydroflow/src/scheduled/graph_ext.rs +++ b/hydroflow/src/scheduled/graph_ext.rs @@ -126,7 +126,7 @@ pub trait GraphExt { W: 'static + Handoff + CanReceive; } -impl<'a> GraphExt for Hydroflow<'a> { +impl GraphExt for Hydroflow<'_> { subgraph_ext!(impl add_subgraph_sink, (recv_port: R), ()); subgraph_ext!( impl add_subgraph_2sink, diff --git a/hydroflow/src/scheduled/net/mod.rs b/hydroflow/src/scheduled/net/mod.rs index 48ffc2e6115f..10664f8a58d3 100644 --- a/hydroflow/src/scheduled/net/mod.rs +++ b/hydroflow/src/scheduled/net/mod.rs @@ -96,7 +96,7 @@ impl Message { } } -impl<'a> Hydroflow<'a> { +impl Hydroflow<'_> { fn register_read_tcp_stream(&mut self, reader: OwnedReadHalf) -> RecvPort> { let reader = FramedRead::new(reader, LengthDelimitedCodec::new()); let (send_port, recv_port) = self.make_edge("tcp ingress handoff"); diff --git a/hydroflow/src/util/simulation.rs b/hydroflow/src/util/simulation.rs index f1611be636e7..86b2bc785644 100644 --- a/hydroflow/src/util/simulation.rs +++ b/hydroflow/src/util/simulation.rs @@ -177,7 +177,7 @@ fn sink_from_fn(mut f: impl FnMut(T)) -> impl Sink { }) } -impl<'context> TransducerBuilderContext<'context> { +impl TransducerBuilderContext<'_> { /// Create a new inbox on the host with the given interface name. Returns a stream that can /// be read by the transducer using the source_stream hydroflow operator. pub fn new_inbox( diff --git a/hydroflow/src/util/tcp.rs b/hydroflow/src/util/tcp.rs index 5f1cab36003b..9c50c3094160 100644 --- a/hydroflow/src/util/tcp.rs +++ b/hydroflow/src/util/tcp.rs @@ -1,16 +1,16 @@ #![cfg(not(target_arch = "wasm32"))] -use std::cell::RefCell; use std::collections::hash_map::Entry::{Occupied, Vacant}; use std::collections::HashMap; +use std::fmt::Debug; use std::net::SocketAddr; -use std::pin::pin; -use std::rc::Rc; use futures::{SinkExt, StreamExt}; use tokio::net::tcp::{OwnedReadHalf, OwnedWriteHalf}; use tokio::net::{TcpListener, TcpSocket, TcpStream}; +use tokio::select; use tokio::task::spawn_local; +use tokio_stream::StreamMap; use tokio_util::codec::{ BytesCodec, Decoder, Encoder, FramedRead, FramedWrite, LengthDelimitedCodec, LinesCodec, }; @@ -74,69 +74,90 @@ pub type TcpFramedSink = Sender<(T, SocketAddr)>; pub type TcpFramedStream = Receiver::Item, SocketAddr), ::Error>>; +// TODO(mingwei): this temporary code should be replaced with a properly thought out networking system. /// Create a listening tcp socket, and then as new connections come in, receive their data and forward it to a queue. -pub async fn bind_tcp>( +pub async fn bind_tcp( endpoint: SocketAddr, codec: Codec, -) -> Result<(TcpFramedSink, TcpFramedStream, SocketAddr), std::io::Error> { +) -> Result<(TcpFramedSink, TcpFramedStream, SocketAddr), std::io::Error> +where + Item: 'static, + Codec: 'static + Clone + Decoder + Encoder, + >::Error: Debug, +{ let listener = TcpListener::bind(endpoint).await?; let bound_endpoint = listener.local_addr()?; - let (tx_egress, mut rx_egress) = unsync_channel(None); - let (tx_ingress, rx_ingress) = unsync_channel(None); - - let clients = Rc::new(RefCell::new(HashMap::new())); - - spawn_local({ - let clients = clients.clone(); - - async move { - while let Some((payload, addr)) = rx_egress.next().await { - let client = clients.borrow_mut().remove(&addr); - - if let Some(mut sender) = client { - let _ = SinkExt::send(&mut sender, payload).await; - clients.borrow_mut().insert(addr, sender); - } - } - } - }); + let (send_egress, mut recv_egress) = unsync_channel::<(Item, SocketAddr)>(None); + let (send_ingres, recv_ingres) = unsync_channel(None); spawn_local(async move { + let send_ingress = send_ingres; + // Map of `addr -> peers`, to send messages to. + let mut peers_send = HashMap::new(); + // `StreamMap` of `addr -> peers`, to receive messages from. Automatically removes streams + // when they disconnect. + let mut peers_recv = StreamMap::>::new(); + loop { - let (stream, peer_addr) = if let Ok((stream, _)) = listener.accept().await { - if let Ok(peer_addr) = stream.peer_addr() { - (stream, peer_addr) - } else { - continue; + // Calling methods in a loop, futures must be cancel-safe. + select! { + // `biased` means the cases will be prioritized in the order they are listed. + // First we accept any new connections + // This is not strictly neccessary, but lets us do our internal work (send outgoing + // messages) before accepting more work (receiving more messages, accepting new + // clients). + biased; + // Send outgoing messages. + msg_send = recv_egress.next() => { + let Some((payload, peer_addr)) = msg_send else { + // `None` if the send side has been dropped (no more send messages will ever come). + continue; + }; + let Some(stream) = peers_send.get_mut(&peer_addr) else { + tracing::warn!("Dropping message to non-connected peer: {}", peer_addr); + continue; + }; + if let Err(err) = SinkExt::send(stream, payload).await { + tracing::error!("IO or codec error sending message to peer {}, disconnecting: {:?}", peer_addr, err); + peers_send.remove(&peer_addr); // `Drop` disconnects. + }; } - } else { - continue; - }; - - let mut tx_ingress = tx_ingress.clone(); - - let (send, recv) = tcp_framed(stream, codec.clone()); - - // TODO: Using peer_addr here as the key is a little bit sketchy. - // It's possible that a client could send a message, disconnect, then another client connects from the same IP address (and the same src port), and then the response could be sent to that new client. - // This can be solved by using monotonically increasing IDs for each new client, but would break the similarity with the UDP versions of this function. - clients.borrow_mut().insert(peer_addr, send); - - spawn_local({ - let clients = clients.clone(); - async move { - let mapped = recv.map(|x| Ok(x.map(|x| (x, peer_addr)))); - let _ = tx_ingress.send_all(&mut pin!(mapped)).await; - - clients.borrow_mut().remove(&peer_addr); + // Receive incoming messages. + msg_recv = peers_recv.next(), if !peers_recv.is_empty() => { + // If `peers_recv` is empty then `next()` will immediately return `None` which + // would cause the loop to spin. + let Some((peer_addr, payload_result)) = msg_recv else { + continue; // => `peers_recv.is_empty()`. + }; + if let Err(err) = send_ingress.send(payload_result.map(|payload| (payload, peer_addr))).await { + tracing::error!("Error passing along received message: {:?}", err); + } } - }); + // Accept new clients. + new_peer = listener.accept() => { + let Ok((stream, _addr)) = new_peer else { + continue; + }; + let Ok(peer_addr) = stream.peer_addr() else { + continue; + }; + let (peer_send, peer_recv) = tcp_framed(stream, codec.clone()); + + // TODO: Using peer_addr here as the key is a little bit sketchy. + // It's possible that a peer could send a message, disconnect, then another peer connects from the + // same IP address (and the same src port), and then the response could be sent to that new client. + // This can be solved by using monotonically increasing IDs for each new peer, but would break the + // similarity with the UDP versions of this function. + peers_send.insert(peer_addr, peer_send); + peers_recv.insert(peer_addr, peer_recv); + } + } } }); - Ok((tx_egress, rx_ingress, bound_endpoint)) + Ok((send_egress, recv_ingres, bound_endpoint)) } /// The inverse of [`bind_tcp`]. @@ -144,37 +165,69 @@ pub async fn bind_tcp> /// When messages enqueued into the returned sender, tcp sockets will be created and connected as /// necessary to send out the requests. As the responses come back, they will be forwarded to the /// returned receiver. -pub fn connect_tcp>( - codec: Codec, -) -> (TcpFramedSink, TcpFramedStream) { - let (tx_egress, mut rx_egress) = unsync_channel(None); - let (tx_ingress, rx_ingress) = unsync_channel(None); +pub fn connect_tcp(codec: Codec) -> (TcpFramedSink, TcpFramedStream) +where + Item: 'static, + Codec: 'static + Clone + Decoder + Encoder, + >::Error: Debug, +{ + let (send_egress, mut recv_egress) = unsync_channel(None); + let (send_ingres, recv_ingres) = unsync_channel(None); spawn_local(async move { - let mut streams = HashMap::new(); + let send_ingres = send_ingres; + // Map of `addr -> peers`, to send messages to. + let mut peers_send = HashMap::new(); + // `StreamMap` of `addr -> peers`, to receive messages from. Automatically removes streams + // when they disconnect. + let mut peers_recv = StreamMap::new(); - while let Some((payload, addr)) = rx_egress.next().await { - let stream = match streams.entry(addr) { - Occupied(entry) => entry.into_mut(), - Vacant(entry) => { - let socket = TcpSocket::new_v4().unwrap(); - let stream = socket.connect(addr).await.unwrap(); - - let (send, recv) = tcp_framed(stream, codec.clone()); - - let mut tx_ingress = tx_ingress.clone(); - spawn_local(async move { - let mapped = recv.map(|x| Ok(x.map(|x| (x, addr)))); - let _ = tx_ingress.send_all(&mut pin!(mapped)).await; - }); - - entry.insert(send) + loop { + // Calling methods in a loop, futures must be cancel-safe. + select! { + // `biased` means the cases will be prioritized in the order they are listed. + // This is not strictly neccessary, but lets us do our internal work (send outgoing + // messages) before accepting more work (receiving more messages). + biased; + // Send outgoing messages. + msg_send = recv_egress.next() => { + let Some((payload, peer_addr)) = msg_send else { + // `None` if the send side has been dropped (no more send messages will ever come). + continue; + }; + + let stream = match peers_send.entry(peer_addr) { + Occupied(entry) => entry.into_mut(), + Vacant(entry) => { + let socket = TcpSocket::new_v4().unwrap(); + let stream = socket.connect(peer_addr).await.unwrap(); + + let (peer_send, peer_recv) = tcp_framed(stream, codec.clone()); + + peers_recv.insert(peer_addr, peer_recv); + entry.insert(peer_send) + } + }; + + if let Err(err) = stream.send(payload).await { + tracing::error!("IO or codec error sending message to peer {}, disconnecting: {:?}", peer_addr, err); + peers_send.remove(&peer_addr); // `Drop` disconnects. + } } - }; - - let _ = stream.send(payload).await; + // Receive incoming messages. + msg_recv = peers_recv.next(), if !peers_recv.is_empty() => { + // If `peers_recv` is empty then `next()` will immediately return `None` which + // would cause the loop to spin. + let Some((peer_addr, payload_result)) = msg_recv else { + continue; // => `peers_recv.is_empty()`. + }; + if let Err(err) = send_ingres.send(payload_result.map(|payload| (payload, peer_addr))).await { + tracing::error!("Error passing along received message: {:?}", err); + } + } + } } }); - (tx_egress, rx_ingress) + (send_egress, recv_ingres) } diff --git a/hydroflow/tests/snapshots/surface_examples__example_1_simplest.snap b/hydroflow/tests/snapshots/surface_examples__example_1_simplest.snap index fa30505c69cd..065e174f4cb3 100644 --- a/hydroflow/tests/snapshots/surface_examples__example_1_simplest.snap +++ b/hydroflow/tests/snapshots/surface_examples__example_1_simplest.snap @@ -12,4 +12,3 @@ Hello 6 Hello 7 Hello 8 Hello 9 - diff --git a/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_dot.snap b/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_dot.snap index e8a4194cc706..dae12d839db5 100644 --- a/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_dot.snap +++ b/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_dot.snap @@ -81,4 +81,3 @@ digraph { } } } - diff --git a/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_mermaid.snap b/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_mermaid.snap index 9a8e0c4a1c46..7b6a31512589 100644 --- a/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_mermaid.snap +++ b/hydroflow/tests/snapshots/surface_lattice_bimorphism__cartesian_product@graphvis_mermaid.snap @@ -67,4 +67,3 @@ subgraph sg_4v1 ["sg_4v1 stratum 1"] 9v1 end end - diff --git a/hydroflow/tests/snapshots/surface_singleton__fold_singleton@graphvis_mermaid.snap b/hydroflow/tests/snapshots/surface_singleton__fold_singleton@graphvis_mermaid.snap index cfc332878447..3775b3febceb 100644 --- a/hydroflow/tests/snapshots/surface_singleton__fold_singleton@graphvis_mermaid.snap +++ b/hydroflow/tests/snapshots/surface_singleton__fold_singleton@graphvis_mermaid.snap @@ -53,4 +53,3 @@ subgraph sg_3v1 ["sg_3v1 stratum 1"] 3v1 end end - diff --git a/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_dot.snap b/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_dot.snap index 74d09d7f66a3..3a4356ee0bc7 100644 --- a/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_dot.snap +++ b/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_dot.snap @@ -61,4 +61,3 @@ digraph { } } } - diff --git a/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_mermaid.snap b/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_mermaid.snap index 54cd4484ba3c..3a8ee979cc01 100644 --- a/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_mermaid.snap +++ b/hydroflow/tests/snapshots/surface_singleton__multi_tick@graphvis_mermaid.snap @@ -53,4 +53,3 @@ subgraph sg_2v1 ["sg_2v1 stratum 0"] 3v1 end end - diff --git a/hydroflow/tests/surface_lattice_bimorphism.rs b/hydroflow/tests/surface_lattice_bimorphism.rs index 401b0953018f..30ff17165576 100644 --- a/hydroflow/tests/surface_lattice_bimorphism.rs +++ b/hydroflow/tests/surface_lattice_bimorphism.rs @@ -2,9 +2,14 @@ use std::collections::{HashMap, HashSet}; use hydroflow::util::collect_ready; use hydroflow::{assert_graphvis_snapshots, hydroflow_syntax}; +use lattices::ght::lattice::{DeepJoinLatticeBimorphism, GhtBimorphism}; +use lattices::ght::GeneralizedHashTrieNode; use lattices::map_union::{KeyedBimorphism, MapUnionHashMap, MapUnionSingletonMap}; use lattices::set_union::{CartesianProductBimorphism, SetUnionHashSet, SetUnionSingletonSet}; +use lattices::GhtType; use multiplatform_test::multiplatform_test; +use variadics::variadic_collections::VariadicHashSet; +use variadics::CloneVariadic; #[multiplatform_test] pub fn test_cartesian_product() { @@ -134,3 +139,50 @@ pub fn test_cartesian_product_tick_state() { &*collect_ready::, _>(&mut out_recv) ); } + +#[test] +fn test_ght_join_bimorphism() { + type MyGhtATrie = GhtType!(u32, u64, u16 => &'static str: VariadicHashSet); + type MyGhtBTrie = GhtType!(u32, u64, u16 => &'static str: VariadicHashSet); + + type JoinSchema = variadics::var_type!(u32, u64, u16, &'static str, &'static str); + + type MyNodeBim = <(MyGhtATrie, MyGhtBTrie) as DeepJoinLatticeBimorphism< + VariadicHashSet, + >>::DeepJoinLatticeBimorphism; + type MyBim = GhtBimorphism; + + let mut hf = hydroflow_syntax! { + lhs = source_iter([ + var_expr!(123, 2, 5, "hello"), + var_expr!(50, 1, 1, "hi"), + var_expr!(5, 1, 7, "hi"), + var_expr!(5, 1, 7, "bye"), + ]) + -> map(|row| MyGhtATrie::new_from([row])) + -> state::<'tick, MyGhtATrie>(); + rhs = source_iter([ + var_expr!(5, 1, 8, "hi"), + var_expr!(5, 1, 7, "world"), + var_expr!(5, 1, 7, "folks"), + var_expr!(10, 1, 2, "hi"), + var_expr!(12, 10, 98, "bye"), + ]) + -> map(|row| MyGhtBTrie::new_from([row])) + -> state::<'tick, MyGhtBTrie>(); + + lhs[items] -> [0]my_join; + rhs[items] -> [1]my_join; + + + my_join = lattice_bimorphism(MyBim::default(), #lhs, #rhs) + -> lattice_reduce() + -> enumerate() + -> inspect(|x| println!("{:?} {:#?}", context.current_tick(), x)) + -> flat_map(|(_num, ght)| ght.recursive_iter().map(::clone_ref_var).collect::>()) + -> null(); + // -> for_each(|x| println!("{:#?}\n", x)); + }; + // hf.meta_graph().unwrap().open_mermaid(&Default::default()); + hf.run_available(); +} diff --git a/hydroflow/tests/surface_lattice_generalized_hash_trie.rs b/hydroflow/tests/surface_lattice_generalized_hash_trie.rs new file mode 100644 index 000000000000..ece19b084ab9 --- /dev/null +++ b/hydroflow/tests/surface_lattice_generalized_hash_trie.rs @@ -0,0 +1,73 @@ +use hydroflow::hydroflow_syntax; +use hydroflow::lattices::ght::lattice::{DeepJoinLatticeBimorphism, GhtBimorphism}; +use hydroflow::lattices::ght::GeneralizedHashTrieNode; +use hydroflow::lattices::GhtType; +use hydroflow::util::collect_ready; +use hydroflow::variadics::{var_expr, var_type}; +use variadics::variadic_collections::VariadicHashSet; // Import the Insert trait + +#[test] +fn test_basic() { + type MyGht = GhtType!(u16, u32 => u64: VariadicHashSet); + type FlatTup = var_type!(u16, u32, u64); + let input: Vec = vec![ + var_expr!(42, 314, 43770), + var_expr!(42, 315, 43770), + var_expr!(42, 314, 30619), + var_expr!(43, 10, 600), + ]; + let mut merged = MyGht::default(); + for i in input.clone() { + merged.insert(i); + } + println!("merged: {:?}", merged); + let mut df = hydroflow_syntax! { + source_iter(input) + -> map(|t| MyGht::new_from(vec![t])) + -> lattice_fold::<'static>(MyGht::default) + -> inspect(|t| println!("{:?}", t)) + -> assert(|x: &MyGht| x.eq(&merged)) + -> null(); + }; + df.run_available(); +} + +#[test] +fn test_join() { + type MyGht = GhtType!(u8 => u16: VariadicHashSet); + type ResultGht = GhtType!(u8 => u16, u16: VariadicHashSet); + let (out_send, out_recv) = hydroflow::util::unbounded_channel::<_>(); + + let r = vec![ + var_expr!(1, 10), + var_expr!(2, 20), + var_expr!(3, 30), + var_expr!(4, 40), + ]; + let s = vec![var_expr!(1, 10), var_expr!(5, 50)]; + + type MyNodeBim = <(MyGht, MyGht) as DeepJoinLatticeBimorphism< + VariadicHashSet, + >>::DeepJoinLatticeBimorphism; + type MyBim = GhtBimorphism; + + let mut df = hydroflow_syntax! { + R = source_iter(r) + -> map(|t| MyGht::new_from([t])) + -> state::(); + S = source_iter(s) + -> map(|t| MyGht::new_from([t])) + -> state::(); + R[items] -> [0]my_join; + S[items] -> [1]my_join; + my_join = lattice_bimorphism(MyBim::default(), #R, #S) + -> lattice_reduce() + -> for_each(|x| out_send.send(x).unwrap()); + }; + df.run_available(); + + assert_eq!( + &[ResultGht::new_from(vec![var_expr!(1, 10, 10),])], + &*collect_ready::, _>(out_recv) + ); +} diff --git a/hydroflow/tests/surface_warnings.rs b/hydroflow/tests/surface_warnings.rs index ae71f41c5aee..fa9826083cd5 100644 --- a/hydroflow/tests/surface_warnings.rs +++ b/hydroflow/tests/surface_warnings.rs @@ -17,7 +17,7 @@ fn test_degenerate_union() { { source_iter([1, 2, 3]) -> union() -> for_each(|x| result_send.send(x).unwrap()); }, - "Warning: `union` should have at least 2 input(s), actually has 1.\n --> $FILE:0:0", + "Warning: `union` should have at least 2 input(s), actually has 1.\n --> $FILE:2:38", }; df.run_available(); @@ -30,7 +30,7 @@ fn test_empty_union() { { union() -> for_each(|x: usize| println!("{}", x)); }, - "Warning: `union` should have at least 2 input(s), actually has 0.\n --> $FILE:0:0", + "Warning: `union` should have at least 2 input(s), actually has 0.\n --> $FILE:2:12", }; df.run_available(); } @@ -43,7 +43,7 @@ fn test_degenerate_tee() { { source_iter([1, 2, 3]) -> tee() -> for_each(|x| result_send.send(x).unwrap()); }, - "Warning: `tee` should have at least 2 output(s), actually has 1.\n --> $FILE:0:0" + "Warning: `tee` should have at least 2 output(s), actually has 1.\n --> $FILE:2:38" }; df.run_available(); @@ -59,7 +59,7 @@ fn test_empty_tee() { { source_iter([1, 2, 3]) -> inspect(|&x| output_inner.borrow_mut().push(x)) -> tee(); }, - "Warning: `tee` should have at least 2 output(s), actually has 0.\n --> $FILE:0:0", + "Warning: `tee` should have at least 2 output(s), actually has 0.\n --> $FILE:2:89", }; df.run_available(); @@ -86,7 +86,7 @@ pub fn test_warped_diamond() { nodes -> [0]init; new_node[1] -> map(|n| (n, 'b')) -> [1]init; }, - "Warning: `union` should have at least 2 input(s), actually has 1.\n --> $FILE:0:0", + "Warning: `union` should have at least 2 input(s), actually has 1.\n --> $FILE:3:20", }; df.run_available(); } @@ -111,8 +111,8 @@ pub fn test_warped_diamond_2() { ntwk = source_iter([4, 5, 6]) -> tee(); }, - "Warning: `union` should have at least 2 input(s), actually has 1.\n --> $FILE:0:0", - "Warning: `tee` should have at least 2 output(s), actually has 0.\n --> $FILE:0:0", + "Warning: `union` should have at least 2 input(s), actually has 1.\n --> $FILE:3:20", + "Warning: `tee` should have at least 2 output(s), actually has 0.\n --> $FILE:16:45", }; hf.run_available(); } diff --git a/hydroflow_datalog_core/Cargo.toml b/hydroflow_datalog_core/Cargo.toml index c2ee69bf0eac..f669063d3107 100644 --- a/hydroflow_datalog_core/Cargo.toml +++ b/hydroflow_datalog_core/Cargo.toml @@ -22,11 +22,11 @@ quote = "1.0.35" slotmap = "1.0.0" syn = { version = "2.0.46", features = [ "parsing", "extra-traits" ] } proc-macro2 = "1.0.74" -rust-sitter = "0.4.2" +rust-sitter = "0.4.3" hydroflow_lang = { path = "../hydroflow_lang", version = "^0.9.0" } [build-dependencies] -rust-sitter-tool = "0.4.2" +rust-sitter-tool = "0.4.3" [dev-dependencies] insta = "1.39" diff --git a/hydroflow_lang/src/graph/ops/anti_join_multiset.rs b/hydroflow_lang/src/graph/ops/anti_join_multiset.rs index 3af7e569eca1..cf9a1e9441d4 100644 --- a/hydroflow_lang/src/graph/ops/anti_join_multiset.rs +++ b/hydroflow_lang/src/graph/ops/anti_join_multiset.rs @@ -2,12 +2,12 @@ use quote::{quote_spanned, ToTokens}; use syn::parse_quote; use super::{ - DelayType, OpInstGenerics, OperatorCategory, OperatorConstraints, - OperatorInstance, OperatorWriteOutput, Persistence, PortIndexValue, WriteContextArgs, RANGE_0, - RANGE_1, + DelayType, OpInstGenerics, OperatorCategory, OperatorConstraints, OperatorInstance, + OperatorWriteOutput, Persistence, PortIndexValue, WriteContextArgs, RANGE_0, RANGE_1, }; use crate::diagnostic::{Diagnostic, Level}; +// This implementation is largely redundant to ANTI_JOIN and should be DRY'ed /// > 2 input streams the first of type (K, T), the second of type K, /// > with output type (K, T) /// @@ -22,8 +22,6 @@ use crate::diagnostic::{Diagnostic, Level}; /// source_iter(vec!["dog", "cat", "gorilla"]) -> [neg]diff; /// diff = anti_join_multiset() -> assert_eq([("elephant", 3), ("elephant", 3)]); /// ``` - -// This implementation is largely redundant to ANTI_JOIN and should be DRY'ed pub const ANTI_JOIN_MULTISET: OperatorConstraints = OperatorConstraints { name: "anti_join_multiset", categories: &[OperatorCategory::MultiIn], diff --git a/hydroflow_plus/src/builder/built.rs b/hydroflow_plus/src/builder/built.rs index fd8659a0c12a..4caf767f0a6d 100644 --- a/hydroflow_plus/src/builder/built.rs +++ b/hydroflow_plus/src/builder/built.rs @@ -18,7 +18,7 @@ pub struct BuiltFlow<'a> { pub(super) _phantom: PhantomData<&'a mut &'a ()>, } -impl<'a> Drop for BuiltFlow<'a> { +impl Drop for BuiltFlow<'_> { fn drop(&mut self) { if !self.used { panic!("Dropped BuiltFlow without instantiating, you may have forgotten to call `compile` or `deploy`."); @@ -26,15 +26,12 @@ impl<'a> Drop for BuiltFlow<'a> { } } -impl<'a> BuiltFlow<'a> { +impl BuiltFlow<'_> { pub fn ir(&self) -> &Vec { &self.ir } - pub fn optimize_with( - mut self, - f: impl FnOnce(Vec) -> Vec, - ) -> BuiltFlow<'a> { + pub fn optimize_with(mut self, f: impl FnOnce(Vec) -> Vec) -> Self { self.used = true; BuiltFlow { ir: f(std::mem::take(&mut self.ir)), diff --git a/hydroflow_plus/src/builder/mod.rs b/hydroflow_plus/src/builder/mod.rs index 3950a08a183e..593b7fb23ffc 100644 --- a/hydroflow_plus/src/builder/mod.rs +++ b/hydroflow_plus/src/builder/mod.rs @@ -9,9 +9,10 @@ use quote::quote; use runtime_support::FreeVariable; use stageleft::*; +use super::staging_util::get_this_crate; use crate::ir::HfPlusLeaf; use crate::location::{Cluster, ExternalProcess, Process}; -use crate::RuntimeContext; +use crate::{ClusterId, RuntimeContext}; pub mod built; pub mod deploy; @@ -31,13 +32,20 @@ pub struct FlowStateInner { pub type FlowState = Rc>; -#[derive(Copy, Clone)] -pub struct ClusterIds<'a> { +pub struct ClusterIds<'a, C> { pub(crate) id: usize, - pub(crate) _phantom: PhantomData<&'a mut &'a Vec>, + pub(crate) _phantom: PhantomData<&'a mut &'a C>, } -impl<'a> FreeVariable<&'a Vec> for ClusterIds<'a> { +impl Clone for ClusterIds<'_, C> { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for ClusterIds<'_, C> {} + +impl<'a, C> FreeVariable<&'a Vec>> for ClusterIds<'a, C> { fn to_tokens(self) -> (Option, Option) where Self: Sized, @@ -46,19 +54,33 @@ impl<'a> FreeVariable<&'a Vec> for ClusterIds<'a> { &format!("__hydroflow_plus_cluster_ids_{}", self.id), Span::call_site(), ); - (None, Some(quote! { #ident })) + let root = get_this_crate(); + let c_type = quote_type::(); + ( + None, + Some( + quote! { unsafe { ::std::mem::transmute::<_, &::std::vec::Vec<#root::ClusterId<#c_type>>>(#ident) } }, + ), + ) } } -impl<'a> Quoted<'a, &'a Vec> for ClusterIds<'a> {} +impl<'a, C> Quoted<'a, &'a Vec>> for ClusterIds<'a, C> {} -#[derive(Copy, Clone)] -pub(crate) struct ClusterSelfId<'a> { +pub(crate) struct ClusterSelfId<'a, C> { pub(crate) id: usize, - pub(crate) _phantom: PhantomData<&'a mut &'a u32>, + pub(crate) _phantom: PhantomData<&'a mut &'a C>, } -impl<'a> FreeVariable for ClusterSelfId<'a> { +impl Clone for ClusterSelfId<'_, C> { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for ClusterSelfId<'_, C> {} + +impl FreeVariable> for ClusterSelfId<'_, C> { fn to_tokens(self) -> (Option, Option) where Self: Sized, @@ -67,11 +89,16 @@ impl<'a> FreeVariable for ClusterSelfId<'a> { &format!("__hydroflow_plus_cluster_self_id_{}", self.id), Span::call_site(), ); - (None, Some(quote! { #ident })) + let root = get_this_crate(); + let c_type: syn::Type = quote_type::(); + ( + None, + Some(quote! { #root::ClusterId::<#c_type>::from_raw(#ident) }), + ) } } -impl<'a> Quoted<'a, u32> for ClusterSelfId<'a> {} +impl<'a, C> Quoted<'a, ClusterId> for ClusterSelfId<'a, C> {} pub struct FlowBuilder<'a> { flow_state: FlowState, @@ -91,7 +118,7 @@ pub struct FlowBuilder<'a> { _phantom: PhantomData<&'a mut &'a ()>, } -impl<'a> Drop for FlowBuilder<'a> { +impl Drop for FlowBuilder<'_> { fn drop(&mut self) { if !self.finalized { panic!("Dropped FlowBuilder without finalizing, you may have forgotten to call `with_default_optimize`, `optimize_with`, or `finalize`."); @@ -99,7 +126,7 @@ impl<'a> Drop for FlowBuilder<'a> { } } -impl<'a> QuotedContext for FlowBuilder<'a> { +impl QuotedContext for FlowBuilder<'_> { fn create() -> Self { FlowBuilder::new() } diff --git a/hydroflow_plus/src/deploy/deploy_graph.rs b/hydroflow_plus/src/deploy/deploy_graph.rs index e7fecc6e7167..218fbda3f5b5 100644 --- a/hydroflow_plus/src/deploy/deploy_graph.rs +++ b/hydroflow_plus/src/deploy/deploy_graph.rs @@ -14,7 +14,7 @@ use hydro_deploy::hydroflow_crate::tracing_options::TracingOptions; use hydro_deploy::hydroflow_crate::HydroflowCrateService; use hydro_deploy::{CustomService, Deployment, Host, HydroflowCrate}; use hydroflow::futures::StreamExt; -use hydroflow::util::deploy::ConnectedSource; +use hydroflow::util::deploy::{ConnectedSink, ConnectedSource}; use nameof::name_of; use serde::de::DeserializeOwned; use serde::Serialize; @@ -29,7 +29,6 @@ use super::trybuild::{compile_graph_trybuild, create_trybuild}; use super::{ClusterSpec, Deploy, ExternalSpec, Node, ProcessSpec, RegisterPort}; use crate::futures::SinkExt; use crate::lang::graph::HydroflowGraph; -use crate::util::deploy::ConnectedSink; pub struct HydroDeploy {} @@ -575,7 +574,7 @@ impl Node for DeployExternal { fn update_meta(&mut self, _meta: &Self::Meta) {} } -impl<'a> ExternalSpec<'a, HydroDeploy> for Arc { +impl ExternalSpec<'_, HydroDeploy> for Arc { fn build(self, _id: usize, _name_hint: &str) -> DeployExternal { DeployExternal { next_port: Rc::new(RefCell::new(0)), @@ -754,7 +753,7 @@ impl DeployProcessSpec { } } -impl<'a> ProcessSpec<'a, HydroDeploy> for DeployProcessSpec { +impl ProcessSpec<'_, HydroDeploy> for DeployProcessSpec { fn build(self, id: usize, _name_hint: &str) -> DeployNode { DeployNode { id, @@ -765,7 +764,7 @@ impl<'a> ProcessSpec<'a, HydroDeploy> for DeployProcessSpec { } } -impl<'a> ProcessSpec<'a, HydroDeploy> for TrybuildHost { +impl ProcessSpec<'_, HydroDeploy> for TrybuildHost { fn build(mut self, id: usize, name_hint: &str) -> DeployNode { self.name_hint = Some(format!("{} (process {id})", name_hint)); DeployNode { @@ -786,7 +785,7 @@ impl DeployClusterSpec { } } -impl<'a> ClusterSpec<'a, HydroDeploy> for DeployClusterSpec { +impl ClusterSpec<'_, HydroDeploy> for DeployClusterSpec { fn build(self, id: usize, _name_hint: &str) -> DeployCluster { DeployCluster { id, @@ -800,7 +799,7 @@ impl<'a> ClusterSpec<'a, HydroDeploy> for DeployClusterSpec { } } -impl<'a> ClusterSpec<'a, HydroDeploy> for Vec { +impl ClusterSpec<'_, HydroDeploy> for Vec { fn build(self, id: usize, name_hint: &str) -> DeployCluster { let name_hint = format!("{} (cluster {id})", name_hint); DeployCluster { diff --git a/hydroflow_plus/src/deploy/deploy_runtime.rs b/hydroflow_plus/src/deploy/deploy_runtime.rs index afbf9250e0f0..ad81b8b76d22 100644 --- a/hydroflow_plus/src/deploy/deploy_runtime.rs +++ b/hydroflow_plus/src/deploy/deploy_runtime.rs @@ -1,11 +1,10 @@ use std::collections::HashMap; -use serde::{Deserialize, Serialize}; -use stageleft::{q, Quoted, RuntimeData}; - -use crate::util::deploy::{ +use hydroflow::util::deploy::{ ConnectedDemux, ConnectedDirect, ConnectedSink, ConnectedSource, ConnectedTagged, DeployPorts, }; +use serde::{Deserialize, Serialize}; +use stageleft::{q, Quoted, RuntimeData}; #[derive(Default, Serialize, Deserialize)] pub struct HydroflowPlusMeta { diff --git a/hydroflow_plus/src/deploy/in_memory_graph.rs b/hydroflow_plus/src/deploy/in_memory_graph.rs index a794dbb8c32e..aeee8233c8cf 100644 --- a/hydroflow_plus/src/deploy/in_memory_graph.rs +++ b/hydroflow_plus/src/deploy/in_memory_graph.rs @@ -4,7 +4,7 @@ use super::{LocalDeploy, Node, ProcessSpec}; pub struct SingleProcessGraph {} -impl<'a> LocalDeploy<'a> for SingleProcessGraph { +impl LocalDeploy<'_> for SingleProcessGraph { type Process = SingleNode; type Cluster = SingleNode; type ExternalProcess = SingleNode; @@ -24,7 +24,7 @@ impl<'a> LocalDeploy<'a> for SingleProcessGraph { } } -impl<'a> ProcessSpec<'a, SingleProcessGraph> for () { +impl ProcessSpec<'_, SingleProcessGraph> for () { fn build(self, _id: usize, _name_hint: &str) -> SingleNode { SingleNode {} } @@ -56,7 +56,7 @@ impl Node for SingleNode { pub struct MultiGraph {} -impl<'a> LocalDeploy<'a> for MultiGraph { +impl LocalDeploy<'_> for MultiGraph { type Process = MultiNode; type Cluster = MultiNode; type ExternalProcess = MultiNode; @@ -76,7 +76,7 @@ impl<'a> LocalDeploy<'a> for MultiGraph { } } -impl<'a> ProcessSpec<'a, MultiGraph> for () { +impl ProcessSpec<'_, MultiGraph> for () { fn build(self, _id: usize, _name_hint: &str) -> MultiNode { MultiNode {} } diff --git a/hydroflow_plus/src/deploy/macro_runtime.rs b/hydroflow_plus/src/deploy/macro_runtime.rs index 4f4e395f45da..a565b20fb561 100644 --- a/hydroflow_plus/src/deploy/macro_runtime.rs +++ b/hydroflow_plus/src/deploy/macro_runtime.rs @@ -2,12 +2,12 @@ use std::cell::RefCell; use std::pin::Pin; use std::rc::Rc; +use hydroflow::util::deploy::DeployPorts; use stageleft::{Quoted, RuntimeData}; use super::HydroflowPlusMeta; use crate::deploy::{ClusterSpec, Deploy, ExternalSpec, Node, ProcessSpec, RegisterPort}; use crate::lang::graph::HydroflowGraph; -use crate::util::deploy::DeployPorts; pub struct DeployRuntime {} @@ -295,7 +295,7 @@ impl Node for DeployRuntimeCluster { } } -impl<'a> ProcessSpec<'a, DeployRuntime> for () { +impl ProcessSpec<'_, DeployRuntime> for () { fn build(self, _id: usize, _name_hint: &str) -> DeployRuntimeNode { DeployRuntimeNode { next_port: Rc::new(RefCell::new(0)), @@ -303,7 +303,7 @@ impl<'a> ProcessSpec<'a, DeployRuntime> for () { } } -impl<'cli> ClusterSpec<'cli, DeployRuntime> for () { +impl ClusterSpec<'_, DeployRuntime> for () { fn build(self, _id: usize, _name_hint: &str) -> DeployRuntimeCluster { DeployRuntimeCluster { next_port: Rc::new(RefCell::new(0)), @@ -311,7 +311,7 @@ impl<'cli> ClusterSpec<'cli, DeployRuntime> for () { } } -impl<'cli> ExternalSpec<'cli, DeployRuntime> for () { +impl ExternalSpec<'_, DeployRuntime> for () { fn build(self, _id: usize, _name_hint: &str) -> DeployRuntimeNode { panic!() } diff --git a/hydroflow_plus/src/ir.rs b/hydroflow_plus/src/ir.rs index 5630e01ce800..62d1604b2b1c 100644 --- a/hydroflow_plus/src/ir.rs +++ b/hydroflow_plus/src/ir.rs @@ -1,6 +1,7 @@ use core::panic; use std::cell::RefCell; use std::collections::{BTreeMap, HashMap}; +use std::fmt::Debug; use std::ops::Deref; use std::rc::Rc; @@ -36,7 +37,7 @@ impl ToTokens for DebugExpr { } } -impl std::fmt::Debug for DebugExpr { +impl Debug for DebugExpr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0.to_token_stream()) } @@ -47,7 +48,7 @@ pub enum DebugInstantiate { Finalized(syn::Expr, syn::Expr, Option>), } -impl std::fmt::Debug for DebugInstantiate { +impl Debug for DebugInstantiate { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "") } @@ -56,7 +57,7 @@ impl std::fmt::Debug for DebugInstantiate { #[derive(Clone)] pub struct DebugPipelineFn(pub Rc Pipeline + 'static>); -impl std::fmt::Debug for DebugPipelineFn { +impl Debug for DebugPipelineFn { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "") } @@ -208,6 +209,59 @@ impl HfPlusLeaf { } } +type PrintedTees = RefCell, usize>)>>; +thread_local! { + static PRINTED_TEES: PrintedTees = const { RefCell::new(None) }; +} + +pub fn dbg_dedup_tee(f: impl FnOnce() -> T) -> T { + PRINTED_TEES.with(|printed_tees| { + let mut printed_tees_mut = printed_tees.borrow_mut(); + *printed_tees_mut = Some((0, HashMap::new())); + drop(printed_tees_mut); + + let ret = f(); + + let mut printed_tees_mut = printed_tees.borrow_mut(); + *printed_tees_mut = None; + + ret + }) +} + +pub struct TeeNode(pub Rc>); + +impl Debug for TeeNode { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + PRINTED_TEES.with(|printed_tees| { + let mut printed_tees_mut_borrow = printed_tees.borrow_mut(); + let printed_tees_mut = printed_tees_mut_borrow.as_mut(); + + if let Some(printed_tees_mut) = printed_tees_mut { + if let Some(existing) = printed_tees_mut + .1 + .get(&(self.0.as_ref() as *const RefCell)) + { + write!(f, "", existing) + } else { + let next_id = printed_tees_mut.0; + printed_tees_mut.0 += 1; + printed_tees_mut + .1 + .insert(self.0.as_ref() as *const RefCell, next_id); + drop(printed_tees_mut_borrow); + write!(f, ": ", next_id)?; + Debug::fmt(&self.0.borrow(), f) + } + } else { + drop(printed_tees_mut_borrow); + write!(f, ": ")?; + Debug::fmt(&self.0.borrow(), f) + } + }) + } +} + /// An intermediate node in a Hydroflow+ graph, which consumes data /// from upstream nodes and emits data to downstream nodes. #[derive(Debug)] @@ -225,7 +279,7 @@ pub enum HfPlusNode { }, Tee { - inner: Rc>, + inner: TeeNode, }, Persist(Box), @@ -383,19 +437,19 @@ impl<'a> HfPlusNode { HfPlusNode::Tee { inner } => { if let Some(transformed) = - seen_tees.get(&(inner.as_ref() as *const RefCell)) + seen_tees.get(&(inner.0.as_ref() as *const RefCell)) { - *inner = transformed.clone(); + *inner = TeeNode(transformed.clone()); } else { let transformed_cell = Rc::new(RefCell::new(HfPlusNode::Placeholder)); seen_tees.insert( - inner.as_ref() as *const RefCell, + inner.0.as_ref() as *const RefCell, transformed_cell.clone(), ); - let mut orig = inner.replace(HfPlusNode::Placeholder); + let mut orig = inner.0.replace(HfPlusNode::Placeholder); transform(&mut orig, seen_tees); *transformed_cell.borrow_mut() = orig; - *inner = transformed_cell; + *inner = TeeNode(transformed_cell); } } @@ -598,11 +652,13 @@ impl<'a> HfPlusNode { } HfPlusNode::Tee { inner } => { - if let Some(ret) = built_tees.get(&(inner.as_ref() as *const RefCell)) { + if let Some(ret) = built_tees.get(&(inner.0.as_ref() as *const RefCell)) + { ret.clone() } else { let (inner_ident, inner_location_id) = inner + .0 .borrow() .emit(graph_builders, built_tees, next_stmt_id); @@ -618,7 +674,7 @@ impl<'a> HfPlusNode { }); built_tees.insert( - inner.as_ref() as *const RefCell, + inner.0.as_ref() as *const RefCell, (tee_ident.clone(), inner_location_id), ); diff --git a/hydroflow_plus/src/lib.rs b/hydroflow_plus/src/lib.rs index 7c986128bd8f..5acf5ac634bc 100644 --- a/hydroflow_plus/src/lib.rs +++ b/hydroflow_plus/src/lib.rs @@ -25,7 +25,7 @@ pub mod singleton; pub use singleton::{Optional, Singleton}; pub mod location; -pub use location::{Cluster, Location, Process}; +pub use location::{Cluster, ClusterId, Location, Process}; pub mod deploy; pub use deploy::{ClusterSpec, Deploy, ProcessSpec}; @@ -43,6 +43,8 @@ pub mod profiler; pub mod properties; +mod staging_util; + #[derive(Clone)] pub struct RuntimeContext<'a> { _phantom: PhantomData<&'a mut &'a ()>, @@ -62,7 +64,7 @@ pub struct HfCompiled<'a, ID> { _phantom: PhantomData<&'a mut &'a ID>, } -impl<'a, ID> HfCompiled<'a, ID> { +impl HfCompiled<'_, ID> { pub fn hydroflow_ir(&self) -> &BTreeMap { &self.hydroflow_ir } diff --git a/hydroflow_plus/src/location.rs b/hydroflow_plus/src/location.rs index b4a6b7a9ef5f..7e4a5e428bb5 100644 --- a/hydroflow_plus/src/location.rs +++ b/hydroflow_plus/src/location.rs @@ -1,3 +1,5 @@ +use std::fmt::{Debug, Display}; +use std::hash::Hash; use std::marker::PhantomData; use std::time::Duration; @@ -6,8 +8,8 @@ use hydroflow::futures::stream::Stream as FuturesStream; use hydroflow::{tokio, tokio_stream}; use proc_macro2::Span; use serde::de::DeserializeOwned; -use serde::Serialize; -use stageleft::{q, Quoted}; +use serde::{Deserialize, Serialize}; +use stageleft::{q, quote_type, Quoted}; use super::builder::{ClusterIds, ClusterSelfId, FlowState}; use crate::cycle::{CycleCollection, CycleCollectionWithInitial}; @@ -282,7 +284,7 @@ pub struct ExternalProcess<'a, P> { pub(crate) _phantom: PhantomData<&'a &'a mut P>, } -impl<'a, P> Clone for ExternalProcess<'a, P> { +impl

Clone for ExternalProcess<'_, P> { fn clone(&self) -> Self { ExternalProcess { id: self.id, @@ -366,7 +368,7 @@ impl<'a, P> ExternalProcess<'a, P> { to_key: None, serialize_pipeline: None, instantiate_fn: crate::ir::DebugInstantiate::Building(), - deserialize_pipeline: Some(crate::stream::deserialize_bincode::(false)), + deserialize_pipeline: Some(crate::stream::deserialize_bincode::(None)), input: Box::new(HfPlusNode::Source { source: HfPlusSource::ExternalNetwork(), location_kind: LocationId::ExternalProcess(self.id), @@ -383,7 +385,7 @@ pub struct Process<'a, P> { pub(crate) _phantom: PhantomData<&'a &'a mut P>, } -impl<'a, P> Clone for Process<'a, P> { +impl

Clone for Process<'_, P> { fn clone(&self) -> Self { Process { id: self.id, @@ -403,6 +405,98 @@ impl<'a, P> Location<'a> for Process<'a, P> { } } +#[repr(transparent)] +pub struct ClusterId { + pub raw_id: u32, + pub(crate) _phantom: PhantomData, +} + +impl Debug for ClusterId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "ClusterId::<{}>({})", + std::any::type_name::(), + self.raw_id + ) + } +} + +impl Display for ClusterId { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!( + f, + "ClusterId::<{}>({})", + std::any::type_name::(), + self.raw_id + ) + } +} + +impl Clone for ClusterId { + fn clone(&self) -> Self { + *self + } +} + +impl Copy for ClusterId {} + +impl Serialize for ClusterId { + fn serialize(&self, serializer: S) -> Result + where + S: serde::ser::Serializer, + { + self.raw_id.serialize(serializer) + } +} + +impl<'de, C> Deserialize<'de> for ClusterId { + fn deserialize(deserializer: D) -> Result + where + D: serde::de::Deserializer<'de>, + { + u32::deserialize(deserializer).map(|id| ClusterId { + raw_id: id, + _phantom: PhantomData, + }) + } +} + +impl PartialEq for ClusterId { + fn eq(&self, other: &Self) -> bool { + self.raw_id == other.raw_id + } +} + +impl Eq for ClusterId {} + +impl PartialOrd for ClusterId { + fn partial_cmp(&self, other: &Self) -> Option { + Some(self.cmp(other)) + } +} + +impl Ord for ClusterId { + fn cmp(&self, other: &Self) -> std::cmp::Ordering { + self.raw_id.cmp(&other.raw_id) + } +} + +impl Hash for ClusterId { + fn hash(&self, state: &mut H) { + self.raw_id.hash(state) + } +} + +impl ClusterId { + pub fn from_raw(id: u32) -> Self { + ClusterId { + raw_id: id, + _phantom: PhantomData, + } + } +} + pub struct Cluster<'a, C> { pub(crate) id: usize, pub(crate) flow_state: FlowState, @@ -410,14 +504,14 @@ pub struct Cluster<'a, C> { } impl<'a, C> Cluster<'a, C> { - pub fn self_id(&self) -> impl Quoted<'a, u32> + Copy + 'a { + pub fn self_id(&self) -> impl Quoted<'a, ClusterId> + Copy + 'a { ClusterSelfId { id: self.id, _phantom: PhantomData, } } - pub fn members(&self) -> impl Quoted<'a, &'a Vec> + Copy + 'a { + pub fn members(&self) -> impl Quoted<'a, &'a Vec>> + Copy + 'a { ClusterIds { id: self.id, _phantom: PhantomData, @@ -425,7 +519,7 @@ impl<'a, C> Cluster<'a, C> { } } -impl<'a, C> Clone for Cluster<'a, C> { +impl Clone for Cluster<'_, C> { fn clone(&self) -> Self { Cluster { id: self.id, @@ -450,7 +544,7 @@ pub trait CanSend<'a, To: Location<'a>>: Location<'a> { type Out; fn is_demux() -> bool; - fn is_tagged() -> bool; + fn tagged_type() -> Option; } impl<'a, P1, P2> CanSend<'a, Process<'a, P2>> for Process<'a, P1> { @@ -461,47 +555,47 @@ impl<'a, P1, P2> CanSend<'a, Process<'a, P2>> for Process<'a, P1> { false } - fn is_tagged() -> bool { - false + fn tagged_type() -> Option { + None } } impl<'a, P1, C2> CanSend<'a, Cluster<'a, C2>> for Process<'a, P1> { - type In = (u32, T); + type In = (ClusterId, T); type Out = T; fn is_demux() -> bool { true } - fn is_tagged() -> bool { - false + fn tagged_type() -> Option { + None } } impl<'a, C1, P2> CanSend<'a, Process<'a, P2>> for Cluster<'a, C1> { type In = T; - type Out = (u32, T); + type Out = (ClusterId, T); fn is_demux() -> bool { false } - fn is_tagged() -> bool { - true + fn tagged_type() -> Option { + Some(quote_type::()) } } impl<'a, C1, C2> CanSend<'a, Cluster<'a, C2>> for Cluster<'a, C1> { - type In = (u32, T); - type Out = (u32, T); + type In = (ClusterId, T); + type Out = (ClusterId, T); fn is_demux() -> bool { true } - fn is_tagged() -> bool { - true + fn tagged_type() -> Option { + Some(quote_type::()) } } @@ -513,7 +607,7 @@ impl<'a, P1, E2> CanSend<'a, ExternalProcess<'a, E2>> for Process<'a, P1> { false } - fn is_tagged() -> bool { - false + fn tagged_type() -> Option { + None } } diff --git a/hydroflow_plus/src/persist_pullup.rs b/hydroflow_plus/src/persist_pullup.rs index ffe4f8d30e8d..007e4b7b2e7e 100644 --- a/hydroflow_plus/src/persist_pullup.rs +++ b/hydroflow_plus/src/persist_pullup.rs @@ -13,22 +13,22 @@ fn persist_pullup_node( HfPlusNode::Delta(box HfPlusNode::Persist(box behind_persist)) => behind_persist, HfPlusNode::Tee { inner } => { - if persist_pulled_tees.contains(&(inner.as_ref() as *const RefCell)) { + if persist_pulled_tees.contains(&(inner.0.as_ref() as *const RefCell)) { HfPlusNode::Persist(Box::new(HfPlusNode::Tee { - inner: inner.clone(), + inner: TeeNode(inner.0.clone()), })) - } else if matches!(*inner.borrow(), HfPlusNode::Persist(_)) { - persist_pulled_tees.insert(inner.as_ref() as *const RefCell); + } else if matches!(*inner.0.borrow(), HfPlusNode::Persist(_)) { + persist_pulled_tees.insert(inner.0.as_ref() as *const RefCell); if let HfPlusNode::Persist(box behind_persist) = - inner.replace(HfPlusNode::Placeholder) + inner.0.replace(HfPlusNode::Placeholder) { - *inner.borrow_mut() = behind_persist; + *inner.0.borrow_mut() = behind_persist; } else { unreachable!() } HfPlusNode::Persist(Box::new(HfPlusNode::Tee { - inner: inner.clone(), + inner: TeeNode(inner.0.clone()), })) } else { HfPlusNode::Tee { inner } diff --git a/hydroflow_plus/src/singleton.rs b/hydroflow_plus/src/singleton.rs index 64d5e8f64f2d..411404226967 100644 --- a/hydroflow_plus/src/singleton.rs +++ b/hydroflow_plus/src/singleton.rs @@ -7,7 +7,7 @@ use stageleft::{q, IntoQuotedMut, Quoted}; use crate::builder::FlowState; use crate::cycle::{CycleCollection, CycleCollectionWithInitial, CycleComplete}; -use crate::ir::{HfPlusLeaf, HfPlusNode, HfPlusSource}; +use crate::ir::{HfPlusLeaf, HfPlusNode, HfPlusSource, TeeNode}; use crate::location::{Location, LocationId}; use crate::stream::{Bounded, NoTick, Tick, Unbounded}; use crate::Stream; @@ -168,7 +168,7 @@ impl<'a, T: Clone, W, C, N: Location<'a>> Clone for Singleton { if !matches!(self.ir_node.borrow().deref(), HfPlusNode::Tee { .. }) { let orig_ir_node = self.ir_node.replace(HfPlusNode::Placeholder); *self.ir_node.borrow_mut() = HfPlusNode::Tee { - inner: Rc::new(RefCell::new(orig_ir_node)), + inner: TeeNode(Rc::new(RefCell::new(orig_ir_node))), }; } @@ -177,7 +177,7 @@ impl<'a, T: Clone, W, C, N: Location<'a>> Clone for Singleton { location_kind: self.location_kind, flow_state: self.flow_state.clone(), ir_node: HfPlusNode::Tee { - inner: inner.clone(), + inner: TeeNode(inner.0.clone()), } .into(), _phantom: PhantomData, @@ -465,7 +465,7 @@ impl<'a, T: Clone, W, C, N: Location<'a>> Clone for Optional { if !matches!(self.ir_node.borrow().deref(), HfPlusNode::Tee { .. }) { let orig_ir_node = self.ir_node.replace(HfPlusNode::Placeholder); *self.ir_node.borrow_mut() = HfPlusNode::Tee { - inner: Rc::new(RefCell::new(orig_ir_node)), + inner: TeeNode(Rc::new(RefCell::new(orig_ir_node))), }; } @@ -474,7 +474,7 @@ impl<'a, T: Clone, W, C, N: Location<'a>> Clone for Optional { location_kind: self.location_kind, flow_state: self.flow_state.clone(), ir_node: HfPlusNode::Tee { - inner: inner.clone(), + inner: TeeNode(inner.0.clone()), } .into(), _phantom: PhantomData, diff --git a/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee-2.snap b/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee-2.snap index 91e05076c486..15f9404ce942 100644 --- a/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee-2.snap +++ b/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee-2.snap @@ -9,15 +9,13 @@ expression: optimized.ir() Map { f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: persist_pullup :: tests :: * ; | v | v + 1 }), input: Tee { - inner: RefCell { - value: Source { - source: Iter( - { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, - ), - location_kind: Process( - 0, - ), - }, + inner: : Source { + source: Iter( + { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, + ), + location_kind: Process( + 0, + ), }, }, }, @@ -29,15 +27,13 @@ expression: optimized.ir() Map { f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: persist_pullup :: tests :: * ; | v | v + 1 }), input: Tee { - inner: RefCell { - value: Source { - source: Iter( - { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, - ), - location_kind: Process( - 0, - ), - }, + inner: : Source { + source: Iter( + { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, + ), + location_kind: Process( + 0, + ), }, }, }, diff --git a/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee.snap b/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee.snap index 2c6cfb398142..441cdcbfca74 100644 --- a/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee.snap +++ b/hydroflow_plus/src/snapshots/hydroflow_plus__persist_pullup__tests__persist_pullup_behind_tee.snap @@ -10,22 +10,20 @@ expression: built.ir() Map { f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: persist_pullup :: tests :: * ; | v | v + 1 }), input: Tee { - inner: RefCell { - value: Persist( - Unpersist( - Persist( - Source { - source: Iter( - { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, - ), - location_kind: Process( - 0, - ), - }, - ), + inner: : Persist( + Unpersist( + Persist( + Source { + source: Iter( + { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, + ), + location_kind: Process( + 0, + ), + }, ), ), - }, + ), }, }, ), @@ -38,22 +36,20 @@ expression: built.ir() Map { f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: persist_pullup :: tests :: * ; | v | v + 1 }), input: Tee { - inner: RefCell { - value: Persist( - Unpersist( - Persist( - Source { - source: Iter( - { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, - ), - location_kind: Process( - 0, - ), - }, - ), + inner: : Persist( + Unpersist( + Persist( + Source { + source: Iter( + { use crate :: __staged :: persist_pullup :: tests :: * ; 0 .. 10 }, + ), + location_kind: Process( + 0, + ), + }, ), ), - }, + ), }, }, ), diff --git a/hydroflow_plus/src/staging_util.rs b/hydroflow_plus/src/staging_util.rs new file mode 100644 index 000000000000..86e5088bcb24 --- /dev/null +++ b/hydroflow_plus/src/staging_util.rs @@ -0,0 +1,14 @@ +use proc_macro2::{Span, TokenStream}; +use quote::quote; + +pub fn get_this_crate() -> TokenStream { + let hydroflow_crate = proc_macro_crate::crate_name("hydroflow_plus") + .expect("hydroflow_plus should be present in `Cargo.toml`"); + match hydroflow_crate { + proc_macro_crate::FoundCrate::Itself => quote! { hydroflow_plus }, + proc_macro_crate::FoundCrate::Name(name) => { + let ident = syn::Ident::new(&name, Span::call_site()); + quote! { #ident } + } + } +} diff --git a/hydroflow_plus/src/stream.rs b/hydroflow_plus/src/stream.rs index 159c1814ae1b..89b1d8476b2b 100644 --- a/hydroflow_plus/src/stream.rs +++ b/hydroflow_plus/src/stream.rs @@ -7,20 +7,19 @@ use std::rc::Rc; use hydroflow::bytes::Bytes; use hydroflow::futures::Sink; use hydroflow_lang::parse::Pipeline; -use proc_macro2::{Span, TokenStream}; -use quote::quote; use serde::de::DeserializeOwned; use serde::Serialize; use stageleft::{q, IntoQuotedMut, Quoted}; use syn::parse_quote; -use crate::builder::FlowState; +use super::staging_util::get_this_crate; +use crate::builder::{self, FlowState}; use crate::cycle::{CycleCollection, CycleComplete}; -use crate::ir::{DebugInstantiate, HfPlusLeaf, HfPlusNode, HfPlusSource}; +use crate::ir::{DebugInstantiate, HfPlusLeaf, HfPlusNode, HfPlusSource, TeeNode}; use crate::location::{ CanSend, ExternalBincodeStream, ExternalBytesPort, ExternalProcess, Location, LocationId, }; -use crate::{Cluster, Optional, Singleton}; +use crate::{Cluster, ClusterId, Optional, Process, Singleton}; /// Marks the stream as being unbounded, which means that it is not /// guaranteed to be complete in finite time. @@ -126,7 +125,7 @@ impl<'a, T: Clone, W, C, N: Location<'a>> Clone for Stream { if !matches!(self.ir_node.borrow().deref(), HfPlusNode::Tee { .. }) { let orig_ir_node = self.ir_node.replace(HfPlusNode::Placeholder); *self.ir_node.borrow_mut() = HfPlusNode::Tee { - inner: Rc::new(RefCell::new(orig_ir_node)), + inner: TeeNode(Rc::new(RefCell::new(orig_ir_node))), }; } @@ -135,7 +134,7 @@ impl<'a, T: Clone, W, C, N: Location<'a>> Clone for Stream { location_kind: self.location_kind, flow_state: self.flow_state.clone(), ir_node: HfPlusNode::Tee { - inner: inner.clone(), + inner: TeeNode(inner.0.clone()), } .into(), _phantom: PhantomData, @@ -636,18 +635,6 @@ impl<'a, K: Eq + Hash, V, N: Location<'a>> Stream<(K, V), Bounded, Tick, N> { } } -fn get_this_crate() -> TokenStream { - let hydroflow_crate = proc_macro_crate::crate_name("hydroflow_plus") - .expect("hydroflow_plus should be present in `Cargo.toml`"); - match hydroflow_crate { - proc_macro_crate::FoundCrate::Itself => quote! { hydroflow_plus }, - proc_macro_crate::FoundCrate::Name(name) => { - let ident = syn::Ident::new(&name, Span::call_site()); - quote! { #ident } - } - } -} - fn serialize_bincode(is_demux: bool) -> Pipeline { let root = get_this_crate(); @@ -655,8 +642,8 @@ fn serialize_bincode(is_demux: bool) -> Pipeline { if is_demux { parse_quote! { - map(|(id, data)| { - (id, #root::runtime_support::bincode::serialize::<#t_type>(&data).unwrap().into()) + map(|(id, data): (#root::ClusterId<_>, #t_type)| { + (id.raw_id, #root::runtime_support::bincode::serialize::<#t_type>(&data).unwrap().into()) }) } } else { @@ -668,16 +655,16 @@ fn serialize_bincode(is_demux: bool) -> Pipeline { } } -pub(super) fn deserialize_bincode(tagged: bool) -> Pipeline { +pub(super) fn deserialize_bincode(tagged: Option) -> Pipeline { let root = get_this_crate(); let t_type: syn::Type = stageleft::quote_type::(); - if tagged { + if let Some(c_type) = tagged { parse_quote! { map(|res| { let (id, b) = res.unwrap(); - (id, #root::runtime_support::bincode::deserialize::<#t_type>(&b).unwrap()) + (#root::ClusterId::<#c_type>::from_raw(id), #root::runtime_support::bincode::deserialize::<#t_type>(&b).unwrap()) }) } } else { @@ -690,6 +677,37 @@ pub(super) fn deserialize_bincode(tagged: bool) -> Pipeline } impl<'a, T, W, N: Location<'a>> Stream { + pub fn decouple_process( + self, + other: &Process<'a, P2>, + ) -> Stream> + where + N: CanSend<'a, Process<'a, P2>, In = T, Out = T>, + T: Clone + Serialize + DeserializeOwned, + { + self.send_bincode::, T>(other) + } + + pub fn decouple_cluster( + self, + other: &Cluster<'a, C2>, + ) -> Stream> + where + N: CanSend<'a, Cluster<'a, C2>, In = (ClusterId, T), Out = (Tag, T)>, + T: Clone + Serialize + DeserializeOwned, + { + let self_node_id = match self.location_kind { + LocationId::Cluster(cluster_id) => builder::ClusterSelfId { + id: cluster_id, + _phantom: PhantomData, + }, + _ => panic!("decouple_cluster must be called on a cluster"), + }; + + self.map(q!(move |b| (self_node_id, b.clone()))) + .send_bincode_interleaved(other) + } + pub fn send_bincode, CoreType>( self, other: &N2, @@ -700,7 +718,7 @@ impl<'a, T, W, N: Location<'a>> Stream { { let serialize_pipeline = Some(serialize_bincode::(N::is_demux())); - let deserialize_pipeline = Some(deserialize_bincode::(N::is_tagged())); + let deserialize_pipeline = Some(deserialize_bincode::(N::tagged_type())); Stream::new( other.id(), @@ -766,6 +784,7 @@ impl<'a, T, W, N: Location<'a>> Stream { where N: CanSend<'a, N2, In = T>, { + let root = get_this_crate(); Stream::new( other.id(), self.flow_state, @@ -776,8 +795,10 @@ impl<'a, T, W, N: Location<'a>> Stream { to_key: None, serialize_pipeline: None, instantiate_fn: DebugInstantiate::Building(), - deserialize_pipeline: if N::is_tagged() { - Some(parse_quote!(map(|(id, b)| (id, b.unwrap().freeze())))) + deserialize_pipeline: if let Some(c_type) = N::tagged_type() { + Some( + parse_quote!(map(|(id, b)| (#root::ClusterId<#c_type>::from_raw(id), b.unwrap().freeze()))), + ) } else { Some(parse_quote!(map(|b| b.unwrap().freeze()))) }, @@ -844,7 +865,7 @@ impl<'a, T, W, N: Location<'a>> Stream { other: &Cluster<'a, C2>, ) -> Stream, Unbounded, NoTick, Cluster<'a, C2>> where - N: CanSend<'a, Cluster<'a, C2>, In = (u32, T)>, + N: CanSend<'a, Cluster<'a, C2>, In = (ClusterId, T)>, T: Clone + Serialize + DeserializeOwned, { let ids = other.members(); @@ -861,7 +882,7 @@ impl<'a, T, W, N: Location<'a>> Stream { other: &Cluster<'a, C2>, ) -> Stream> where - N: CanSend<'a, Cluster<'a, C2>, In = (u32, T), Out = (Tag, T)> + 'a, + N: CanSend<'a, Cluster<'a, C2>, In = (ClusterId, T), Out = (Tag, T)> + 'a, T: Clone + Serialize + DeserializeOwned, { self.broadcast_bincode(other).map(q!(|(_, b)| b)) @@ -872,7 +893,7 @@ impl<'a, T, W, N: Location<'a>> Stream { other: &Cluster<'a, C2>, ) -> Stream, Unbounded, NoTick, Cluster<'a, C2>> where - N: CanSend<'a, Cluster<'a, C2>, In = (u32, T)> + 'a, + N: CanSend<'a, Cluster<'a, C2>, In = (ClusterId, T)> + 'a, T: Clone, { let ids = other.members(); @@ -889,7 +910,8 @@ impl<'a, T, W, N: Location<'a>> Stream { other: &Cluster<'a, C2>, ) -> Stream> where - N: CanSend<'a, Cluster<'a, C2>, In = (u32, T), Out = (Tag, Bytes)> + 'a, + N: CanSend<'a, Cluster<'a, C2>, In = (ClusterId, T), Out = (Tag, Bytes)> + + 'a, T: Clone, { self.broadcast_bytes(other).map(q!(|(_, b)| b)) diff --git a/hydroflow_plus_test/examples/two_pc.rs b/hydroflow_plus_test/examples/two_pc.rs new file mode 100644 index 000000000000..df946a70613c --- /dev/null +++ b/hydroflow_plus_test/examples/two_pc.rs @@ -0,0 +1,34 @@ +use hydro_deploy::Deployment; +use hydroflow_plus::deploy::TrybuildHost; + +#[tokio::main] +async fn main() { + let mut deployment = Deployment::new(); + let _localhost = deployment.Localhost(); + + let builder = hydroflow_plus::FlowBuilder::new(); + let num_participants: u32 = 3; + + let (coordinator, participants, client) = + hydroflow_plus_test::cluster::two_pc::two_pc(&builder, num_participants); + + let _rustflags = "-C opt-level=3 -C codegen-units=1 -C strip=none -C debuginfo=2 -C lto=off"; + + let _nodes = builder + .with_default_optimize() + .with_process(&coordinator, TrybuildHost::new(deployment.Localhost())) + .with_cluster( + &participants, + (0..num_participants) + .map(|_| TrybuildHost::new(deployment.Localhost())) + .collect::>(), + ) + .with_process(&client, TrybuildHost::new(deployment.Localhost())) + .deploy(&mut deployment); + + deployment.deploy().await.unwrap(); + + deployment.start().await.unwrap(); + + tokio::signal::ctrl_c().await.unwrap(); +} diff --git a/hydroflow_plus_test/src/cluster/many_to_many.rs b/hydroflow_plus_test/src/cluster/many_to_many.rs index e3aa96870a5e..90adbf03f09b 100644 --- a/hydroflow_plus_test/src/cluster/many_to_many.rs +++ b/hydroflow_plus_test/src/cluster/many_to_many.rs @@ -61,7 +61,7 @@ mod tests { for value in 0..2 { assert_eq!( node_outs.next().unwrap(), - format!("cluster received: ({}, {})", sender, value) + format!("cluster received: (ClusterId::<()>({}), {})", sender, value) ); } } diff --git a/hydroflow_plus_test/src/cluster/map_reduce.rs b/hydroflow_plus_test/src/cluster/map_reduce.rs index 1e76c1fc14eb..95696d5cbcf0 100644 --- a/hydroflow_plus_test/src/cluster/map_reduce.rs +++ b/hydroflow_plus_test/src/cluster/map_reduce.rs @@ -16,7 +16,10 @@ pub fn map_reduce<'a>(flow: &FlowBuilder<'a>) -> (Process<'a, Leader>, Cluster<' let words_partitioned = words .tick_batch() .enumerate() - .map(q!(|(i, w)| ((i % all_ids_vec.len()) as u32, w))) + .map(q!(|(i, w)| ( + ClusterId::from_raw((i % all_ids_vec.len()) as u32), + w + ))) .all_ticks(); words_partitioned diff --git a/hydroflow_plus_test/src/cluster/mod.rs b/hydroflow_plus_test/src/cluster/mod.rs index 1e3bc5374a70..bcc449c3195d 100644 --- a/hydroflow_plus_test/src/cluster/mod.rs +++ b/hydroflow_plus_test/src/cluster/mod.rs @@ -4,3 +4,4 @@ pub mod map_reduce; pub mod paxos; pub mod paxos_bench; pub mod simple_cluster; +pub mod two_pc; diff --git a/hydroflow_plus_test/src/cluster/paxos.rs b/hydroflow_plus_test/src/cluster/paxos.rs index fd0c6e3f784b..488be19c01e4 100644 --- a/hydroflow_plus_test/src/cluster/paxos.rs +++ b/hydroflow_plus_test/src/cluster/paxos.rs @@ -21,11 +21,11 @@ pub trait PaxosPayload: pub struct Ballot { // Note: Important that num comes before id, since Ord is defined lexicographically pub num: u32, - pub id: u32, + pub id: ClusterId, } impl LeaderElected for Ballot { - fn leader_id(&self) -> u32 { + fn leader_id(&self) -> ClusterId { self.id } } @@ -64,12 +64,12 @@ struct P2b

{ } #[expect(clippy::type_complexity, reason = "internal paxos code // TODO")] -pub fn paxos_core<'a, P: PaxosPayload>( +pub fn paxos_core<'a, P: PaxosPayload, R>( flow: &FlowBuilder<'a>, r_to_acceptors_checkpoint: impl FnOnce( &Cluster<'a, Acceptor>, ) -> Stream< - (u32, i32), + (ClusterId, i32), Unbounded, NoTick, Cluster<'a, Acceptor>, @@ -184,16 +184,21 @@ pub fn paxos_core<'a, P: PaxosPayload>( } #[expect(clippy::type_complexity, reason = "internal paxos code // TODO")] -fn acceptor<'a, P: PaxosPayload>( +fn acceptor<'a, P: PaxosPayload, R>( p_to_acceptors_p1a: Stream>, p_to_acceptors_p2a: Stream, Unbounded, NoTick, Cluster<'a, Acceptor>>, - r_to_acceptors_checkpoint: Stream<(u32, i32), Unbounded, NoTick, Cluster<'a, Acceptor>>, + r_to_acceptors_checkpoint: Stream< + (ClusterId, i32), + Unbounded, + NoTick, + Cluster<'a, Acceptor>, + >, proposers: &Cluster<'a, Proposer>, acceptors: &Cluster<'a, Acceptor>, f: usize, ) -> ( - Stream<(u32, P1b

), Unbounded, NoTick, Cluster<'a, Proposer>>, - Stream<(u32, P2b

), Unbounded, NoTick, Cluster<'a, Proposer>>, + Stream<(ClusterId, P1b

), Unbounded, NoTick, Cluster<'a, Proposer>>, + Stream<(ClusterId, P2b

), Unbounded, NoTick, Cluster<'a, Proposer>>, ) { // Get the latest checkpoint sequence per replica let a_checkpoint_largest_seqs = @@ -222,7 +227,10 @@ fn acceptor<'a, P: PaxosPayload>( min_seq, P2a { // Create tuple with checkpoint number and dummy p2a - ballot: Ballot { num: 0, id: 0 }, + ballot: Ballot { + num: 0, + id: ClusterId::from_raw(0) + }, slot: -1, value: Default::default() } @@ -233,7 +241,10 @@ fn acceptor<'a, P: PaxosPayload>( .clone() .map(q!(|p1a| p1a.ballot)) .max() - .unwrap_or(acceptors.singleton(q!(Ballot { num: 0, id: 0 }))); + .unwrap_or(acceptors.singleton(q!(Ballot { + num: 0, + id: ClusterId::from_raw(0) + }))); let a_p2as_to_place_in_log = p_to_acceptors_p2a .clone() .tick_batch() @@ -318,9 +329,15 @@ fn acceptor<'a, P: PaxosPayload>( (a_to_proposers_p1b_new, a_to_proposers_p2b_new) } +#[expect(clippy::type_complexity, reason = "internal paxos code // TODO")] fn p_p2b<'a, P: PaxosPayload>( proposers: &Cluster<'a, Proposer>, - a_to_proposers_p2b: Stream<(u32, P2b

), Unbounded, NoTick, Cluster<'a, Proposer>>, + a_to_proposers_p2b: Stream< + (ClusterId, P2b

), + Unbounded, + NoTick, + Cluster<'a, Proposer>, + >, f: usize, ) -> Stream<(i32, P), Unbounded, NoTick, Cluster<'a, Proposer>> { let (p_broadcasted_p2b_slots_complete_cycle, p_broadcasted_p2b_slots) = proposers.tick_cycle(); @@ -341,8 +358,14 @@ fn p_p2b<'a, P: PaxosPayload>( q!(|| ( 0, P2b { - ballot: Ballot { num: 0, id: 0 }, - max_ballot: Ballot { num: 0, id: 0 }, + ballot: Ballot { + num: 0, + id: ClusterId::from_raw(0) + }, + max_ballot: Ballot { + num: 0, + id: ClusterId::from_raw(0) + }, slot: 0, value: Default::default() } @@ -466,7 +489,12 @@ fn p_p2a<'a, P: PaxosPayload>( #[expect(clippy::type_complexity, reason = "internal paxos code // TODO")] fn p_p1b<'a, P: PaxosPayload>( proposers: &Cluster<'a, Proposer>, - a_to_proposers_p1b: Stream<(u32, P1b

), Unbounded, NoTick, Cluster<'a, Proposer>>, + a_to_proposers_p1b: Stream< + (ClusterId, P1b

), + Unbounded, + NoTick, + Cluster<'a, Proposer>, + >, p_ballot_num: Singleton>, p_has_largest_ballot: Optional<(Ballot, u32), Bounded, Tick, Cluster<'a, Proposer>>, f: usize, @@ -501,7 +529,7 @@ fn p_p1b<'a, P: PaxosPayload>( let p_p1b_highest_entries_and_count = p_relevant_p1bs .clone() .flat_map(q!(|((_, p1b), _)| p1b.accepted.into_iter())) // Convert HashMap log back to stream - .fold_keyed(q!(|| (0, LogValue { ballot: Ballot { num: 0, id: 0 }, value: Default::default() })), q!(|curr_entry, new_entry| { + .fold_keyed(q!(|| (0, LogValue { ballot: Ballot { num: 0, id: ClusterId::from_raw(0) }, value: Default::default() })), q!(|curr_entry, new_entry| { let same_values = new_entry.value == curr_entry.1.value; let higher_ballot = new_entry.ballot > curr_entry.1.ballot; // Increment count if the values are the same @@ -559,10 +587,21 @@ fn p_p1b<'a, P: PaxosPayload>( } // Proposer logic to calculate the largest ballot received so far. +#[expect(clippy::type_complexity, reason = "internal paxos code // TODO")] fn p_max_ballot<'a, P: PaxosPayload>( proposers: &Cluster<'a, Proposer>, - a_to_proposers_p1b: Stream<(u32, P1b

), Unbounded, NoTick, Cluster<'a, Proposer>>, - a_to_proposers_p2b: Stream<(u32, P2b

), Unbounded, NoTick, Cluster<'a, Proposer>>, + a_to_proposers_p1b: Stream< + (ClusterId, P1b

), + Unbounded, + NoTick, + Cluster<'a, Proposer>, + >, + a_to_proposers_p2b: Stream< + (ClusterId, P2b

), + Unbounded, + NoTick, + Cluster<'a, Proposer>, + >, p_to_proposers_i_am_leader: Stream>, ) -> Singleton> { let p_received_p1b_ballots = a_to_proposers_p1b @@ -575,7 +614,10 @@ fn p_max_ballot<'a, P: PaxosPayload>( .union(p_received_p2b_ballots) .union(p_to_proposers_i_am_leader) .max() - .unwrap_or(proposers.singleton(q!(Ballot { num: 0, id: 0 }))) + .unwrap_or(proposers.singleton(q!(Ballot { + num: 0, + id: ClusterId::from_raw(0) + }))) } // Proposer logic to calculate the next ballot number. Expects p_received_max_ballot, the largest ballot received so far. Outputs streams: ballot_num, and has_largest_ballot, which only contains a value if we have the largest ballot. @@ -666,7 +708,7 @@ fn p_p1a<'a>( }), ); // Add random delay depending on node ID so not everyone sends p1a at the same time - let p_leader_expired = proposers.source_interval_delayed(q!(Duration::from_secs((p_id * i_am_leader_check_timeout_delay_multiplier as u32).into())), q!(Duration::from_secs(i_am_leader_check_timeout))) + let p_leader_expired = proposers.source_interval_delayed(q!(Duration::from_secs((p_id.raw_id * i_am_leader_check_timeout_delay_multiplier as u32).into())), q!(Duration::from_secs(i_am_leader_check_timeout))) .cross_singleton(p_latest_received_i_am_leader.clone()) .latest_tick() // .inspect(q!(|v| println!("Proposer checking if leader expired"))) diff --git a/hydroflow_plus_test/src/cluster/paxos_bench.rs b/hydroflow_plus_test/src/cluster/paxos_bench.rs index fdf76683b706..5b72192b093c 100644 --- a/hydroflow_plus_test/src/cluster/paxos_bench.rs +++ b/hydroflow_plus_test/src/cluster/paxos_bench.rs @@ -10,7 +10,7 @@ use stageleft::*; use super::paxos::{paxos_core, Acceptor, Ballot, PaxosPayload, Proposer}; pub trait LeaderElected: Ord + Clone { - fn leader_id(&self) -> u32; + fn leader_id(&self) -> ClusterId; } pub struct Replica {} @@ -97,7 +97,12 @@ pub fn paxos_bench<'a>( fn paxos_with_replica<'a>( flow: &FlowBuilder<'a>, replicas: &Cluster<'a, Replica>, - c_to_proposers: Stream<(u32, ClientPayload), Unbounded, NoTick, Cluster<'a, Client>>, + c_to_proposers: Stream< + (ClusterId, ClientPayload), + Unbounded, + NoTick, + Cluster<'a, Client>, + >, f: usize, i_am_leader_send_timeout: u64, i_am_leader_check_timeout: u64, @@ -107,7 +112,7 @@ fn paxos_with_replica<'a>( Cluster<'a, Proposer>, Cluster<'a, Acceptor>, Stream>, - Stream<(u32, ReplicaPayload), Unbounded, NoTick, Cluster<'a, Replica>>, + Stream<(ClusterId, ReplicaPayload), Unbounded, NoTick, Cluster<'a, Replica>>, ) { let (r_to_acceptors_checkpoint_complete_cycle, r_to_acceptors_checkpoint) = replicas.cycle::>(); @@ -152,7 +157,7 @@ pub fn replica<'a>( checkpoint_frequency: usize, ) -> ( Stream>, - Stream<(u32, ReplicaPayload), Unbounded, NoTick, Cluster<'a, Replica>>, + Stream<(ClusterId, ReplicaPayload), Unbounded, NoTick, Cluster<'a, Replica>>, ) { let (r_buffered_payloads_complete_cycle, r_buffered_payloads) = replicas.tick_cycle(); // p_to_replicas.inspect(q!(|payload: ReplicaPayload| println!("Replica received payload: {:?}", payload))); @@ -239,7 +244,7 @@ pub fn replica<'a>( // Tell clients that the payload has been committed. All ReplicaPayloads contain the client's machine ID (to string) as value. let r_to_clients = p_to_replicas.map(q!(|payload| ( - payload.value.parse::().unwrap(), + ClusterId::from_raw(payload.value.parse::().unwrap()), payload ))); (r_checkpoint_seq_new.all_ticks(), r_to_clients) @@ -250,7 +255,7 @@ fn bench_client<'a, B: LeaderElected + std::fmt::Debug>( clients: &Cluster<'a, Client>, p_to_clients_leader_elected: Stream>, r_to_clients_payload_applied: Stream< - (u32, ReplicaPayload), + (ClusterId, ReplicaPayload), Unbounded, NoTick, Cluster<'a, Client>, @@ -258,7 +263,7 @@ fn bench_client<'a, B: LeaderElected + std::fmt::Debug>( num_clients_per_node: usize, median_latency_window_size: usize, f: usize, -) -> Stream<(u32, ClientPayload), Unbounded, NoTick, Cluster<'a, Client>> { +) -> Stream<(ClusterId, ClientPayload), Unbounded, NoTick, Cluster<'a, Client>> { let c_id = clients.self_id(); // r_to_clients_payload_applied.clone().inspect(q!(|payload: &(u32, ReplicaPayload)| println!("Client received payload: {:?}", payload))); // Only keep the latest leader @@ -278,7 +283,7 @@ fn bench_client<'a, B: LeaderElected + std::fmt::Debug>( leader_ballot.leader_id(), ClientPayload { key: i as u32, - value: c_id.to_string() + value: c_id.raw_id.to_string() } ) ))); @@ -318,7 +323,7 @@ fn bench_client<'a, B: LeaderElected + std::fmt::Debug>( leader_ballot.leader_id(), ClientPayload { key, - value: c_id.to_string() + value: c_id.raw_id.to_string() } ))); let c_to_proposers = c_new_payloads_when_leader_elected @@ -458,7 +463,9 @@ mod tests { let _ = super::paxos_bench(&builder, 1, 1, 1, 1, 1, 1, 1); let built = builder.with_default_optimize(); - insta::assert_debug_snapshot!(built.ir()); + hydroflow_plus::ir::dbg_dedup_tee(|| { + insta::assert_debug_snapshot!(built.ir()); + }); let _ = built.compile::(&RuntimeData::new("FAKE")); } diff --git a/hydroflow_plus_test/src/cluster/pbft.rs b/hydroflow_plus_test/src/cluster/pbft.rs new file mode 100644 index 000000000000..ce128330fa8b --- /dev/null +++ b/hydroflow_plus_test/src/cluster/pbft.rs @@ -0,0 +1,390 @@ +use std::collections::{HashMap, HashSet}; +use std::time::{Duration, SystemTime}; + +use hydroflow_plus::*; +use serde::{Deserialize, Serialize}; +use stageleft::*; +use tokio::time::Instant; + +pub struct Client {} +pub struct Replica {} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct Request { + pub client_id: u32, + pub operation: String, + pub timestamp: u64, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct Reply { + pub view: u32, + pub timestamp: u64, + pub client_id: u32, + pub replica_id: u32, + pub result: String, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct PrePrepare { + pub view: u32, + pub sequence_number: u64, + pub request: Request, + pub digest: String, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct Prepare { + pub view: u32, + pub sequence_number: u64, + pub digest: String, + pub replica_id: u32, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct Commit { + pub view: u32, + pub sequence_number: u64, + pub digest: String, + pub replica_id: u32, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct ViewChange { + pub view: u32, + pub replica_id: u32, + pub last_sequence_number: u64, + pub P: Vec, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct NewView { + pub view: u32, + pub V: Vec, + pub O: Vec, +} + +#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug, Hash)] +pub struct Prepared { + pub view: u32, + pub sequence_number: u64, + pub digest: String, +} + +pub fn pbft<'a>( + flow: &FlowBuilder<'a>, + num_clients_per_node: usize, + f: usize, + throughput_window_size: usize, + view_timeout: u64, +) -> ( + Cluster, + Cluster, +) { + let clients = flow.cluster::(); + let replicas = flow.cluster::(); + + let client_id = flow.cluster_self_id(&clients); + let replica_id = flow.cluster_self_id(&replicas); + + let num_replicas = 3 * f + 1; + + // Define the current view number, starting from 0 + let (current_view_cycle, current_view_stream) = flow.tick_cycle_with_initial( + &replicas, + flow.singleton(&replicas, q!(0u32)).latest_tick(), + ); + let current_view = current_view_stream.latest(); + + // Each replica determines if it's the primary (leader) for the current view + let is_primary = current_view + .map(q!(move |view| (*view % (num_replicas as u32)) == replica_id)) + .latest_tick(); + + // Client sends requests + let client_requests = flow.source_iter(&clients, q!([ + Request { + client_id, + operation: "operation1".to_string(), + timestamp: 1, + }, + Request { + client_id, + operation: "operation2".to_string(), + timestamp: 2, + }, + Request { + client_id, + operation: "operation3".to_string(), + timestamp: 3, + }, + ])); + + // Clients broadcast requests to all replicas + let requests_to_replicas = client_requests.broadcast_bincode(&replicas); + + // Each replica filters requests intended for the current primary + let requests_to_primary = requests_to_replicas + .cross_singleton(current_view.clone()) + .filter(q!(move |(request, view)| { + (*view % (num_replicas as u32)) == replica_id + })) + .map(q!(|(request, _)| request.clone())) + .continue_if(is_primary.clone()); + + // The primary processes the requests and creates PrePrepare messages + let (sequence_number_cycle, sequence_number_stream) = flow.tick_cycle_with_initial( + &replicas, + flow.singleton(&replicas, q!(0u64)).latest_tick(), + ); + let sequence_number = sequence_number_stream.latest(); + + let pre_prepares = requests_to_primary + .enumerate() + .cross_singleton(current_view.clone()) + .cross_singleton(sequence_number.clone()) + .map(q!(move |(((index, request), view), seq_num)| PrePrepare { + view: *view, + sequence_number: *seq_num + index as u64 + 1, + request: request.clone(), + digest: format!("{:?}", request), + })) + .persist(); + + // Update the sequence number for the next batch + let next_sequence_number = sequence_number + .cross_singleton(pre_prepares.clone().count()) + .map(q!(|(seq_num, count)| seq_num + count as u64)) + .defer_tick(); + sequence_number_cycle.complete(next_sequence_number.into()); + + // The primary broadcasts PrePrepare messages to all replicas + let pre_prepares_broadcast = pre_prepares.clone().broadcast_bincode(&replicas); + + // Replicas receive PrePrepare messages + let received_pre_prepares = pre_prepares_broadcast.tick_batch(); + + // Replicas verify PrePrepare messages and create Prepare messages + let prepares = received_pre_prepares + .cross_singleton(replica_id.clone()) + .map(q!(|pre_prepare, replica_id| Prepare { + view: pre_prepare.view, + sequence_number: pre_prepare.sequence_number, + digest: pre_prepare.digest.clone(), + replica_id, + })) + .broadcast_bincode(&replicas); + + // Replicas receive Prepare messages + let received_prepares = prepares.tick_batch(); + + // Collect Prepare messages + let prepare_counts = received_prepares + .map(q!(|prepare| ((prepare.view, prepare.sequence_number, prepare.digest.clone()), prepare.replica_id))) + .fold_keyed( + q!(|| HashSet::new()), + q!(|set, replica_id| { set.insert(replica_id); }), + ); + + // Check if enough Prepare messages have been collected to move to the Commit phase + let prepared_certificates = prepare_counts + .filter(q!(move |(_, set)| set.len() >= 2 * f)) + .map(q!(|(key, _)| Prepared { + view: key.0, + sequence_number: key.1, + digest: key.2.clone(), + })) + .persist(); + + // Replicas create Commit messages and broadcast them + let commits = prepared_certificates + .cross_singleton(replica_id.clone()) + .map(q!(|cert, replica_id| Commit { + view: cert.view, + sequence_number: cert.sequence_number, + digest: cert.digest.clone(), + replica_id, + })) + .broadcast_bincode(&replicas); + + // Replicas receive Commit messages + let received_commits = commits.tick_batch(); + + // Collect Commit messages + let commit_counts = received_commits + .map(q!(|commit| ((commit.view, commit.sequence_number, commit.digest.clone()), commit.replica_id))) + .fold_keyed( + q!(|| HashSet::new()), + q!(|set, replica_id| { set.insert(replica_id); }), + ); + + // Replicas execute requests after receiving enough Commit messages + let executed_requests = commit_counts + .filter(q!(move |(_, set)| set.len() >= 2 * f + 1)) + .map(q!(|(key, _)| { + println!("Replica {} executed request at view {}, seq {}", replica_id, key.0, key.1); + (key.1, key.2.clone()) + })) + .persist(); + + // Maintain the highest sequence number executed + let highest_sequence_number_stream = executed_requests + .map(q!(|(seq_num, _)| seq_num)) + .max() + .unwrap_or(flow.singleton(&replicas, q!(0u64)).latest_tick()); + + let highest_sequence_number = highest_sequence_number_stream.latest_tick(); + + // View change mechanism + + // Define a timeout to detect primary failure + let timeout_interval = flow + .source_interval(&replicas, q!(Duration::from_secs(view_timeout))) + .latest_tick(); + + // Replicas send ViewChange messages upon timeout + let view_changes = timeout_interval + .cross_singleton(current_view.clone()) + .cross_singleton(replica_id.clone()) + .cross_singleton(highest_sequence_number.clone()) + .cross_singleton(prepared_certificates.clone().collect()) + .map(q!(move |(((((), view), replica_id), last_seq_num), prepared)| ViewChange { + view: *view + 1, + replica_id, + last_sequence_number: *last_seq_num, + P: prepared.clone(), + })) + .broadcast_bincode(&replicas); + + // Replicas receive ViewChange messages + let received_view_changes = view_changes.tick_batch(); + + let view_change_counts = received_view_changes + .map(q!(|vc| (vc.view, vc))) + .fold_keyed( + q!(|| Vec::new()), + q!(|vec, vc| { vec.push(vc); }), + ); + + // Check if enough ViewChange messages have been collected to form a NewView + let new_views = view_change_counts + .filter(q!(move |(_, vec)| vec.len() >= 2 * f + 1)) + .map(q!(|(view, vcs)| NewView { + view, + V: vcs.clone(), + O: vec![], // This should be constructed based on V and P + })) + .broadcast_bincode(&replicas); + + // Replicas receive NewView messages and update the current view + let received_new_views = new_views.tick_batch(); + + let updated_view = received_new_views + .map(q!(|nv| nv.view)) + .latest_tick(); + + // Update the current view + current_view_cycle.complete(updated_view.into()); + + // Each replica determines if it is the new primary after view change + let new_is_primary = updated_view + .map(q!(move |view| (*view % (num_replicas as u32)) == replica_id)) + .latest_tick(); + + // The new primary processes any pending requests from ViewChange messages and generates new PrePrepare messages + // For simplicity, we'll assume there are no pending requests in this example + // In practice, you would reconstruct O based on the V and P collections in the NewView message + + // Benchmark code similar to Paxos implementation + + // Track throughput + + // Define a timer for statistics output + let stats_interval = flow.source_interval(&clients, q!(Duration::from_secs(1))); + + // Collect the number of executed requests + let executed_requests_count = executed_requests + .count() + .continue_unless(stats_interval.clone().latest_tick()) + .map(q!(|count| (count, false))); + + let reset_throughput = stats_interval + .clone() + .latest_tick() + .map(q!(|_| (0usize, true))) + .defer_tick(); + + let throughput = executed_requests_count + .union(reset_throughput) + .all_ticks() + .fold( + q!(|| 0usize), + q!(|(total, (count, reset))| { + if reset { + *total = 0; + } else { + *total += count; + } + }), + ); + + // Output throughput + stats_interval + .cross_singleton(throughput.clone()) + .tick_samples() + .for_each(q!(move |(_, total)| { + println!("Throughput: {} requests/s", total); + })); + + // Latency tracking + + // Create cycles to track request send and execution times + let (request_times_cycle, request_times_stream) = flow.cycle(&clients); + let request_times = request_times_stream.latest_tick(); + + // When clients send requests, record the timestamp + let client_request_times = client_requests + .map(q!(move |_| (client_id, SystemTime::now()))) + .persist(); + + request_times_cycle.complete(client_request_times.into()); + + // When replicas execute requests, record the timestamp + let execution_times = executed_requests + .map(q!(move |(seq_num, digest)| (seq_num, digest, SystemTime::now()))) + .broadcast_bincode(&clients); + + // Clients receive execution times and calculate latency + let latencies = execution_times + .cross_singleton(request_times.clone()) + .map(q!(|((seq_num, digest, exec_time), (client_id, send_time))| { + let latency = exec_time.duration_since(send_time).unwrap_or(Duration::ZERO); + latency.as_millis() + })) + .collect() + .latest_tick(); + + // Calculate average latency over the window + let average_latency = latencies + .map(q!(move |latencies_vec| { + if latencies_vec.is_empty() { + 0 + } else { + let sum: u128 = latencies_vec.iter().sum(); + (sum / latencies_vec.len() as u128) as usize + } + })); + + // Output latency + stats_interval + .cross_singleton(average_latency) + .tick_samples() + .for_each(q!(move |(_, avg_latency)| { + println!("Average Latency: {} ms", avg_latency); + })); + + ( + clients, + replicas, + ) +} diff --git a/hydroflow_plus_test/src/cluster/simple_cluster.rs b/hydroflow_plus_test/src/cluster/simple_cluster.rs index 428c020f49b1..771a7ed1c97b 100644 --- a/hydroflow_plus_test/src/cluster/simple_cluster.rs +++ b/hydroflow_plus_test/src/cluster/simple_cluster.rs @@ -1,6 +1,33 @@ use hydroflow_plus::*; use stageleft::*; +pub fn decouple_cluster<'a>(flow: &FlowBuilder<'a>) -> (Cluster<'a, ()>, Cluster<'a, ()>) { + let cluster1 = flow.cluster(); + let cluster2 = flow.cluster(); + let cluster_self_id = cluster2.self_id(); + let cluster1_self_id = cluster1.self_id(); + cluster1 + .source_iter(q!(vec!(cluster1_self_id))) + // .for_each(q!(|message| println!("hey, {}", message))) + .inspect(q!(|message| println!("Cluster1 node sending message: {}", message))) + .decouple_cluster(&cluster2) + .for_each(q!(move |message| println!( + "My self id is {}, my message is {}", + cluster_self_id, message + ))); + (cluster1, cluster2) +} + +pub fn decouple_process<'a>(flow: &FlowBuilder<'a>) -> (Process<'a, ()>, Process<'a, ()>) { + let process1 = flow.process(); + let process2 = flow.process(); + process1 + .source_iter(q!(0..3)) + .decouple_process(&process2) + .for_each(q!(|message| println!("I received message is {}", message))); + (process1, process2) +} + pub fn simple_cluster<'a>(flow: &FlowBuilder<'a>) -> (Process<'a, ()>, Cluster<'a, ()>) { let process = flow.process(); let cluster = flow.cluster(); @@ -68,7 +95,7 @@ mod tests { for j in 0..5 { assert_eq!( stdout.recv().await.unwrap(), - format!("cluster received: ({}, {}) (self cluster id: {})", i, j, i) + format!("cluster received: (ClusterId::<()>({}), {}) (self cluster id: ClusterId::<()>({}))", i, j, i) ); } } @@ -82,8 +109,82 @@ mod tests { for (i, n) in node_outs.into_iter().enumerate() { assert_eq!( n, - format!("node received: ({}, ({}, {}))", i / 5, i / 5, i % 5) + format!( + "node received: (ClusterId::<()>({}), (ClusterId::<()>({}), {}))", + i / 5, + i / 5, + i % 5 + ) ); } } + + #[tokio::test] + async fn decouple_process() { + let mut deployment = Deployment::new(); + + let builder = hydroflow_plus::FlowBuilder::new(); + let (process1, process2) = super::decouple_process(&builder); + let built = builder.with_default_optimize(); + + let nodes = built + .with_process(&process1, TrybuildHost::new(deployment.Localhost())) + .with_process(&process2, TrybuildHost::new(deployment.Localhost())) + .deploy(&mut deployment); + + deployment.deploy().await.unwrap(); + let mut process2_stdout = nodes.get_process(&process2).stdout().await; + deployment.start().await.unwrap(); + for i in 0..3 { + let expected_message = format!("I received message is {}", i); + assert_eq!(process2_stdout.recv().await.unwrap(), expected_message); + } + } + + #[tokio::test] + async fn decouple_cluster() { + let mut deployment = Deployment::new(); + + let builder = hydroflow_plus::FlowBuilder::new(); + let (cluster1, cluster2) = super::decouple_cluster(&builder); + let built = builder.with_default_optimize(); + + let nodes = built + .with_cluster( + &cluster1, + (0..3) + .map(|_| TrybuildHost::new(deployment.Localhost())) + .collect::>(), + ) + .with_cluster( + &cluster2, + (0..3) + .map(|_| TrybuildHost::new(deployment.Localhost())) + .collect::>(), + ) + .deploy(&mut deployment); + + deployment.deploy().await.unwrap(); + + let cluster2_stdouts = futures::future::join_all( + nodes + .get_cluster(&cluster2) + .members() + .iter() + .map(|node| node.stdout()), + ) + .await; + + deployment.start().await.unwrap(); + + for (i, mut stdout) in cluster2_stdouts.into_iter().enumerate() { + for _j in 0..1 { + let expected_message = format!( + "My self id is ClusterId::<()>({}), my message is ClusterId::<()>({})", + i, i + ); + assert_eq!(stdout.recv().await.unwrap(), expected_message); + } + } + } } diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir.snap index c8bbf0a947ec..70a8dd42e91b 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir.snap @@ -12,7 +12,7 @@ expression: built.ir() f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u64 , u64) , (u64 , u64) , () > ({ use crate :: __staged :: cluster :: compute_pi :: * ; | (inside , total) , (inside_batch , total_batch) | { * inside += inside_batch ; * total += total_batch ; } }), input: Persist( Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , (u64 , u64)) , (u64 , u64) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: compute_pi :: Worker > , (u64 , u64)) , (u64 , u64) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), input: Network { from_location: Cluster( 0, @@ -38,7 +38,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (u64 , u64) > (& b) . unwrap ()) }", + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: compute_pi :: Worker > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (u64 , u64) > (& b) . unwrap ()) }", ], }, ), diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir@surface_graph_1.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir@surface_graph_1.snap index ca6d96f060dc..c73fdb714a8e 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir@surface_graph_1.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__compute_pi__tests__compute_pi_ir@surface_graph_1.snap @@ -3,8 +3,8 @@ source: hydroflow_plus_test/src/cluster/compute_pi.rs expression: ir.surface_syntax_string() --- 1v1 = source_stream ({ use hydroflow_plus :: __staged :: deploy :: deploy_runtime :: * ; let env = FAKE ; let p2_port = "port_0" ; { env . port (p2_port) . connect_local_blocking :: < ConnectedTagged < ConnectedDirect > > () . into_source () } }); -2v1 = map (| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (u64 , u64) > (& b) . unwrap ()) }); -3v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < (u32 , (u64 , u64)) , (u64 , u64) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b })); +2v1 = map (| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: compute_pi :: Worker > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (u64 , u64) > (& b) . unwrap ()) }); +3v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: compute_pi :: Worker > , (u64 , u64)) , (u64 , u64) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b })); 4v1 = reduce :: < 'static > (stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u64 , u64) , (u64 , u64) , () > ({ use crate :: __staged :: cluster :: compute_pi :: * ; | (inside , total) , (inside_batch , total_batch) | { * inside += inside_batch ; * total += total_batch ; } })); 5v1 = source_interval (stageleft :: runtime_support :: type_hint :: < core :: time :: Duration > ({ use crate :: __staged :: cluster :: compute_pi :: * ; Duration :: from_secs (1) })); 6v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < () , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () })); diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__many_to_many__tests__many_to_many.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__many_to_many__tests__many_to_many.snap index 1a04dda0fb11..d58ad11b7168 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__many_to_many__tests__many_to_many.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__many_to_many__tests__many_to_many.snap @@ -4,7 +4,7 @@ expression: built.ir() --- [ ForEach { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , i32) , () > ({ use crate :: __staged :: cluster :: many_to_many :: * ; | n | println ! ("cluster received: {:?}" , n) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < () > , i32) , () > ({ use crate :: __staged :: cluster :: many_to_many :: * ; | n | println ! ("cluster received: {:?}" , n) }), input: Network { from_location: Cluster( 0, @@ -19,7 +19,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < i32 > (& data) . unwrap () . into ()) }", + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , i32) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < i32 > (& data) . unwrap () . into ()) }", ], }, ), @@ -30,13 +30,13 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < i32 > (& b) . unwrap ()) }", + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < () > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < i32 > (& b) . unwrap ()) }", ], }, ), ), input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_0 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < () > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < () > > > (__hydroflow_plus_cluster_ids_0) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), input: Source { source: Iter( { use crate :: __staged :: cluster :: many_to_many :: * ; 0 .. 2 }, diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir.snap index c33d9b128113..c895c3413a7c 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir.snap @@ -9,7 +9,7 @@ expression: built.ir() f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use crate :: __staged :: cluster :: map_reduce :: * ; | total , count | * total += count }), input: Persist( Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , (std :: string :: String , i32)) , (std :: string :: String , i32) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: map_reduce :: Worker > , (std :: string :: String , i32)) , (std :: string :: String , i32) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), input: Network { from_location: Cluster( 1, @@ -35,7 +35,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (std :: string :: String , i32) > (& b) . unwrap ()) }", + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: map_reduce :: Worker > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (std :: string :: String , i32) > (& b) . unwrap ()) }", ], }, ), @@ -61,7 +61,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < std :: string :: String > (& data) . unwrap () . into ()) }", + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , std :: string :: String) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < std :: string :: String > (& data) . unwrap () . into ()) }", ], }, ), @@ -78,7 +78,7 @@ expression: built.ir() ), ), input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , std :: string :: String) , (u32 , std :: string :: String) > ({ use crate :: __staged :: cluster :: map_reduce :: * ; let all_ids_vec = __hydroflow_plus_cluster_ids_1 ; | (i , w) | ((i % all_ids_vec . len ()) as u32 , w) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , std :: string :: String) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: map_reduce :: Worker > , std :: string :: String) > ({ use crate :: __staged :: cluster :: map_reduce :: * ; let all_ids_vec = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: map_reduce :: Worker > > > (__hydroflow_plus_cluster_ids_1) } ; | (i , w) | (ClusterId :: from_raw ((i % all_ids_vec . len ()) as u32) , w) }), input: Enumerate( Map { f: stageleft :: runtime_support :: fn1_type_hint :: < & str , std :: string :: String > ({ use crate :: __staged :: cluster :: map_reduce :: * ; | s | s . to_string () }), diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir@surface_graph_0.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir@surface_graph_0.snap index de23c7f7e01c..06befe0c8323 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir@surface_graph_0.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__map_reduce__tests__map_reduce_ir@surface_graph_0.snap @@ -5,12 +5,12 @@ expression: ir.surface_syntax_string() 1v1 = source_iter ({ use crate :: __staged :: cluster :: map_reduce :: * ; vec ! ["abc" , "abc" , "xyz" , "abc"] }); 2v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < & str , std :: string :: String > ({ use crate :: __staged :: cluster :: map_reduce :: * ; | s | s . to_string () })); 3v1 = enumerate (); -4v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < (usize , std :: string :: String) , (u32 , std :: string :: String) > ({ use crate :: __staged :: cluster :: map_reduce :: * ; let all_ids_vec = __hydroflow_plus_cluster_ids_1 ; | (i , w) | ((i % all_ids_vec . len ()) as u32 , w) })); -5v1 = map (| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < std :: string :: String > (& data) . unwrap () . into ()) }); +4v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < (usize , std :: string :: String) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: map_reduce :: Worker > , std :: string :: String) > ({ use crate :: __staged :: cluster :: map_reduce :: * ; let all_ids_vec = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: map_reduce :: Worker > > > (__hydroflow_plus_cluster_ids_1) } ; | (i , w) | (ClusterId :: from_raw ((i % all_ids_vec . len ()) as u32) , w) })); +5v1 = map (| (id , data) : (hydroflow_plus :: ClusterId < _ > , std :: string :: String) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < std :: string :: String > (& data) . unwrap () . into ()) }); 6v1 = dest_sink ({ use hydroflow_plus :: __staged :: deploy :: deploy_runtime :: * ; let env = FAKE ; let p1_port = "port_0" ; { env . port (p1_port) . connect_local_blocking :: < ConnectedDemux < ConnectedDirect > > () . into_sink () } }); 7v1 = source_stream ({ use hydroflow_plus :: __staged :: deploy :: deploy_runtime :: * ; let env = FAKE ; let p2_port = "port_1" ; { env . port (p2_port) . connect_local_blocking :: < ConnectedTagged < ConnectedDirect > > () . into_source () } }); -8v1 = map (| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (std :: string :: String , i32) > (& b) . unwrap ()) }); -9v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < (u32 , (std :: string :: String , i32)) , (std :: string :: String , i32) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b })); +8v1 = map (| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: map_reduce :: Worker > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (std :: string :: String , i32) > (& b) . unwrap ()) }); +9v1 = map (stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: map_reduce :: Worker > , (std :: string :: String , i32)) , (std :: string :: String , i32) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b })); 10v1 = reduce_keyed :: < 'static > (stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use crate :: __staged :: cluster :: map_reduce :: * ; | total , count | * total += count })); 11v1 = for_each (stageleft :: runtime_support :: fn1_type_hint :: < (std :: string :: String , i32) , () > ({ use crate :: __staged :: cluster :: map_reduce :: * ; | (string , count) | println ! ("{}: {}" , string , count) })); diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__paxos_bench__tests__paxos_ir.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__paxos_bench__tests__paxos_ir.snap index d5aba2eee9ab..f20193cd83b1 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__paxos_bench__tests__paxos_ir.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__paxos_bench__tests__paxos_ir.snap @@ -22,52 +22,34 @@ expression: built.ir() 2, ), input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | { if received_max_ballot > (Ballot { num : ballot_num , id : p_id , }) { received_max_ballot . num + 1 } else { ballot_num } } }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | (received_max_ballot , ballot_num) | { if received_max_ballot > (Ballot { num : ballot_num , id : p_id , }) { received_max_ballot . num + 1 } else { ballot_num } } }), input: CrossSingleton( Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( + inner: : Union( + Reduce { + f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), + input: Persist( + Union( Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), + input: Tee { + inner: : CycleSource { + ident: Ident { + sym: cycle_1, }, + location_kind: Cluster( + 2, + ), }, }, - ), - Tee { - inner: RefCell { - value: CycleSource { + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), + input: Tee { + inner: : CycleSource { ident: Ident { - sym: cycle_0, + sym: cycle_2, }, location_kind: Cluster( 2, @@ -76,44 +58,52 @@ expression: built.ir() }, }, ), + Tee { + inner: : CycleSource { + ident: Ident { + sym: cycle_0, + }, + location_kind: Cluster( + 2, + ), + }, + }, ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, ), + }, + Persist( + Source { + source: Iter( + { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : ClusterId :: from_raw (0) } } ; [e] }, + ), + location_kind: Cluster( + 2, + ), + }, ), - }, + ), }, Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, + inner: : Union( + CycleSource { + ident: Ident { + sym: cycle_3, + }, + location_kind: Cluster( + 2, + ), + }, + Persist( + Source { + source: Iter( + { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, + ), location_kind: Cluster( 2, ), }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), ), - }, + ), }, ), }, @@ -121,234 +111,98 @@ expression: built.ir() ForEach { f: stageleft :: runtime_support :: fn1_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | _ | println ! ("Proposer leader expired") }), input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; move | (_ , latest_received_i_am_leader) | { if let Some (latest_received_i_am_leader) = latest_received_i_am_leader { (Instant :: now () . duration_since (* latest_received_i_am_leader)) > Duration :: from_secs (i_am_leader_check_timeout) } else { true } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , ()) , (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - CrossSingleton( - Source { - source: Stream( - { use hydroflow_plus :: __staged :: location :: * ; let delay = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout_delay_multiplier = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; Duration :: from_secs ((p_id * i_am_leader_check_timeout_delay_multiplier as u32) . into ()) } ; let interval = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; Duration :: from_secs (i_am_leader_check_timeout) } ; tokio_stream :: wrappers :: IntervalStream :: new (tokio :: time :: interval_at (tokio :: time :: Instant :: now () + delay , interval)) }, - ), - location_kind: Cluster( - 2, - ), - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < tokio :: time :: Instant > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < tokio :: time :: Instant > , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | latest , _ | { * latest = Some (Instant :: now ()) ; } }), - input: Persist( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), + inner: : Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; move | (_ , latest_received_i_am_leader) | { if let Some (latest_received_i_am_leader) = latest_received_i_am_leader { (Instant :: now () . duration_since (* latest_received_i_am_leader)) > Duration :: from_secs (i_am_leader_check_timeout) } else { true } } }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < ((tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , ()) , (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + CrossSingleton( + Source { + source: Stream( + { use hydroflow_plus :: __staged :: location :: * ; let delay = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout_delay_multiplier = 1usize ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; Duration :: from_secs ((p_id . raw_id * i_am_leader_check_timeout_delay_multiplier as u32) . into ()) } ; let interval = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; Duration :: from_secs (i_am_leader_check_timeout) } ; tokio_stream :: wrappers :: IntervalStream :: new (tokio :: time :: interval_at (tokio :: time :: Instant :: now () + delay , interval)) }, + ), + location_kind: Cluster( + 2, + ), + }, + Tee { + inner: : Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < tokio :: time :: Instant > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < tokio :: time :: Instant > , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | latest , _ | { * latest = Some (Instant :: now ()) ; } }), + input: Persist( + Tee { + inner: , }, - }, + ), }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), + }, + ), + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Unique( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < ((hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), + input: Tee { + inner: : Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), + Persist( + Tee { + inner: : Inspect { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), + input: Tee { + inner: , }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), + }, }, - }, + ), Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, + inner: , }, ), }, }, }, + ), + }, + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Tee { + inner: : Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), + input: CrossSingleton( + Tee { + inner: , + }, + Tee { + inner: , + }, + ), }, - ), + }, }, - }, + ), }, }, }, }, - ), - }, + }, + ), }, }, }, @@ -361,7 +215,7 @@ expression: built.ir() 2, ), input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos :: Ballot) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), input: Network { from_location: Cluster( 2, @@ -376,7 +230,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& data) . unwrap () . into ()) }", + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos :: Ballot) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& data) . unwrap () . into ()) }", ], }, ), @@ -387,15 +241,15 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& b) . unwrap ()) }", + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& b) . unwrap ()) }", ], }, ), ), input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_2 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > > > (__hydroflow_plus_cluster_ids_2) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ballot_num | Ballot { num : ballot_num , id : p_id } }), + f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | ballot_num | Ballot { num : ballot_num , id : p_id } }), input: Map { f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), input: CrossSingleton( @@ -403,28 +257,7 @@ expression: built.ir() f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), input: CrossSingleton( Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, + inner: , }, Map { f: stageleft :: runtime_support :: fn1_type_hint :: < () , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), @@ -442,182 +275,7 @@ expression: built.ir() Map { f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, + inner: , }, }, ), @@ -637,546 +295,177 @@ expression: built.ir() input: DeferTick( Union( Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Union( Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | max_slot | max_slot + 1 }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | max_slot | max_slot + 1 }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Union( + Tee { + inner: : Reduce { + f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, + inner: : FoldKeyed { + init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : ClusterId :: from_raw (0) } , value : Default :: default () }) }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), + input: FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < ((hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), + input: Tee { + inner: , }, - location_kind: Cluster( - 2, - ), }, }, }, }, }, }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (num_payloads , next_slot) | next_slot + num_payloads as i32 }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , ()) , usize > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; | num_payloads | * num_payloads > 0 }), - input: Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, + Persist( + Source { + source: Iter( + { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; - 1 } ; [e] }, ), - }, - }, - }, - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, location_kind: Cluster( 2, ), }, + ), + ), + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: : CycleSource { + ident: Ident { + sym: cycle_4, + }, + location_kind: Cluster( + 2, + ), + }, + }, + }, }, }, ), }, - ), + }, Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (num_payloads , next_slot) | next_slot + num_payloads as i32 }), input: CrossSingleton( Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , usize , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; | num_payloads | * num_payloads > 0 }), - input: Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , ()) , usize > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Tee { + inner: : Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Client > , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + input: Network { + from_location: Cluster( + 0, + ), + from_key: None, + to_location: Cluster( + 2, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", + ], + }, + ), + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos_bench :: Client > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", + ], }, + ), + ), + input: CycleSource { + ident: Ident { + sym: cycle_0, }, + location_kind: Cluster( + 0, + ), }, }, }, }, }, }, - }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Tee { + inner: : Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; | num_payloads | * num_payloads > 0 }), + input: Tee { + inner: , + }, + }, + }, + }, + ), }, }, + Tee { + inner: , + }, ), }, ), Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Tee { + inner: , + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , usize , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: , }, - ), + }, }, }, - }, + ), }, ), - }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Tee { + inner: , + }, + }, + ), }, }, Map { @@ -1185,2747 +474,117 @@ expression: built.ir() f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), input: CrossSingleton( Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | max_slot | max_slot + 1 }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (num_payloads , next_slot) | next_slot + num_payloads as i32 }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , ()) , usize > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; | num_payloads | * num_payloads > 0 }), - input: Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - }, - }, - }, - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , ()) , i32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , usize , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; | num_payloads | * num_payloads > 0 }), - input: Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - ), - ), - }, - CycleSink { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - input: DeferTick( - Difference( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , (_count , _p2b)) | slot }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , core :: option :: Option < i32 > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (slot , (count , _p2b)) | if count == 2 * f + 1 { Some (slot) } else { None } }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - ), - }, - CycleSink { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - input: DeferTick( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (sender , p2b)) | (sender , p2b) }), - input: AntiJoin( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | (p2b . slot , (sender , p2b)) }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , core :: option :: Option < i32 > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (slot , (count , _p2b)) | if count == 2 * f + 1 { Some (slot) } else { None } }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - }, - ), - }, - ForEach { - f: stageleft :: runtime_support :: fn1_type_hint :: < & str , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | s | println ! ("{}" , s) }), - input: Source { - source: Iter( - { use crate :: __staged :: cluster :: paxos :: * ; ["Acceptors say hello"] }, - ), - location_kind: Cluster( - 3, - ), - }, - }, - CycleSink { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - input: Network { - from_location: Cluster( - 3, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((hydroflow_plus_test :: cluster :: paxos :: P1a , hydroflow_plus_test :: cluster :: paxos :: Ballot) , (i32 , std :: collections :: hash_map :: HashMap < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > >)) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((p1a , max_ballot) , (_prev_checkpoint , log)) | (p1a . ballot . id , P1b { ballot : p1a . ballot , max_ballot , accepted : log }) }), - input: CrossSingleton( - CrossSingleton( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | println ! ("Acceptor received P1a: {:?}" , p1a) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1a) , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ballot_num | P1a { ballot : Ballot { num : ballot_num , id : p_id } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; move | (_ , latest_received_i_am_leader) | { if let Some (latest_received_i_am_leader) = latest_received_i_am_leader { (Instant :: now () . duration_since (* latest_received_i_am_leader)) > Duration :: from_secs (i_am_leader_check_timeout) } else { true } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , ()) , (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - CrossSingleton( - Source { - source: Stream( - { use hydroflow_plus :: __staged :: location :: * ; let delay = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout_delay_multiplier = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; Duration :: from_secs ((p_id * i_am_leader_check_timeout_delay_multiplier as u32) . into ()) } ; let interval = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; Duration :: from_secs (i_am_leader_check_timeout) } ; tokio_stream :: wrappers :: IntervalStream :: new (tokio :: time :: interval_at (tokio :: time :: Instant :: now () + delay , interval)) }, - ), - location_kind: Cluster( - 2, - ), - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < tokio :: time :: Instant > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < tokio :: time :: Instant > , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | latest , _ | { * latest = Some (Instant :: now ()) ; } }), - input: Persist( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - }, - }, - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | p1a . ballot }), - input: Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | println ! ("Acceptor received P1a: {:?}" , p1a) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1a) , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ballot_num | P1a { ballot : Ballot { num : ballot_num , id : p_id } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; move | (_ , latest_received_i_am_leader) | { if let Some (latest_received_i_am_leader) = latest_received_i_am_leader { (Instant :: now () . duration_since (* latest_received_i_am_leader)) > Duration :: from_secs (i_am_leader_check_timeout) } else { true } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , ()) , (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - CrossSingleton( - Source { - source: Stream( - { use hydroflow_plus :: __staged :: location :: * ; let delay = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout_delay_multiplier = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; Duration :: from_secs ((p_id * i_am_leader_check_timeout_delay_multiplier as u32) . into ()) } ; let interval = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; Duration :: from_secs (i_am_leader_check_timeout) } ; tokio_stream :: wrappers :: IntervalStream :: new (tokio :: time :: interval_at (tokio :: time :: Instant :: now () + delay , interval)) }, - ), - location_kind: Cluster( - 2, - ), - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < tokio :: time :: Instant > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < tokio :: time :: Instant > , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | latest , _ | { * latest = Some (Instant :: now ()) ; } }), - input: Persist( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - }, - }, - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 3, - ), - }, - ), - ), - }, - }, - ), - Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < (i32 , std :: collections :: hash_map :: HashMap < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (- 1 , HashMap :: new ()) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (i32 , std :: collections :: hash_map :: HashMap < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > >) , (i32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (prev_checkpoint , log) , (new_checkpoint , p2a) | { if new_checkpoint != - 1 { for slot in * prev_checkpoint .. new_checkpoint { log . remove (& slot) ; } * prev_checkpoint = new_checkpoint ; } else { if p2a . slot > * prev_checkpoint { match log . get (& p2a . slot) { None => { log . insert (p2a . slot , LogValue { ballot : p2a . ballot , value : p2a . value , } ,) ; } Some (prev_p2a) => { if p2a . ballot > prev_p2a . ballot { log . insert (p2a . slot , LogValue { ballot : p2a . ballot , value : p2a . value , } ,) ; } } } ; } } } }), - input: Persist( - Union( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , hydroflow_plus_test :: cluster :: paxos :: Ballot) , core :: option :: Option < (i32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (p2a , max_ballot) | if p2a . ballot >= max_ballot { Some ((- 1 , p2a)) } else { None } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , ()) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , ()) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , u32) , core :: option :: Option < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((slot , (count , entry)) , ballot_num) | if count <= f as u32 { Some (P2a { ballot : Ballot { num : ballot_num , id : p_id , } , slot , value : entry . value , }) } else { None } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , u32) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (slot , ballot_num) | P2a { ballot : Ballot { num : ballot_num , id : p_id } , slot , value : Default :: default () } }), - input: CrossSingleton( - Difference( - FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: ops :: Range < i32 > > ({ use crate :: __staged :: cluster :: paxos :: * ; | max_slot | 0 .. max_slot }), - input: Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: stream :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (((usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , i32) , u32) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (((index , payload) , next_slot) , ballot_num) | P2a { ballot : Ballot { num : ballot_num , id : p_id } , slot : next_slot + index as i32 , value : payload } }), - input: CrossSingleton( - CrossSingleton( - Enumerate( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | p1a . ballot }), - input: Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | println ! ("Acceptor received P1a: {:?}" , p1a) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1a) , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ballot_num | P1a { ballot : Ballot { num : ballot_num , id : p_id } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; move | (_ , latest_received_i_am_leader) | { if let Some (latest_received_i_am_leader) = latest_received_i_am_leader { (Instant :: now () . duration_since (* latest_received_i_am_leader)) > Duration :: from_secs (i_am_leader_check_timeout) } else { true } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , ()) , (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - CrossSingleton( - Source { - source: Stream( - { use hydroflow_plus :: __staged :: location :: * ; let delay = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout_delay_multiplier = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; Duration :: from_secs ((p_id * i_am_leader_check_timeout_delay_multiplier as u32) . into ()) } ; let interval = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; Duration :: from_secs (i_am_leader_check_timeout) } ; tokio_stream :: wrappers :: IntervalStream :: new (tokio :: time :: interval_at (tokio :: time :: Instant :: now () + delay , interval)) }, - ), - location_kind: Cluster( - 2, - ), - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < tokio :: time :: Instant > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < tokio :: time :: Instant > , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | latest , _ | { * latest = Some (Instant :: now ()) ; } }), - input: Persist( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - }, - }, - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 3, - ), - }, - ), - ), - }, - }, - ), - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , (i32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | min_seq | (min_seq , P2a { ballot : Ballot { num : 0 , id : 0 } , slot : - 1 , value : Default :: default () }) }), - input: Delta( - Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new < * curr { * curr = new ; } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_sender , seq) | seq }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , i32) , ()) , (u32 , i32) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: ReduceKeyed { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_seq , seq | { if seq > * curr_seq { * curr_seq = seq ; } } }), - input: Persist( - Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < i32 > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < i32 > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 1, - ), - }, - }, - }, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received == f + 1 { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , (u32 , i32) , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: ReduceKeyed { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_seq , seq | { if seq > * curr_seq { * curr_seq = seq ; } } }), - input: Persist( - Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < i32 > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < i32 > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 1, - ), - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 3, + inner: , + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: , + }, + }, + }, + }, + ), + }, + }, + ), + ), + }, + CycleSink { + ident: Ident { + sym: cycle_5, + }, + location_kind: Cluster( + 2, + ), + input: DeferTick( + Difference( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , (_count , _p2b)) | slot }), + input: Tee { + inner: : Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), + input: Tee { + inner: : FoldKeyed { + init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : ClusterId :: from_raw (0) } , max_ballot : Ballot { num : 0 , id : ClusterId :: from_raw (0) } , slot : 0 , value : Default :: default () }) }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), + input: FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), + input: Tee { + inner: : Union( + Tee { + inner: , + }, + CycleSource { + ident: Ident { + sym: cycle_6, + }, + location_kind: Cluster( + 2, ), }, ), - ), - ), + }, + }, }, - ), - ), + }, + }, + }, + }, + Tee { + inner: : FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , core :: option :: Option < i32 > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (slot , (count , _p2b)) | if count == 2 * f + 1 { Some (slot) } else { None } }), + input: Tee { + inner: , + }, + }, + }, + ), + ), + }, + CycleSink { + ident: Ident { + sym: cycle_6, + }, + location_kind: Cluster( + 2, + ), + input: DeferTick( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (sender , p2b)) | (sender , p2b) }), + input: AntiJoin( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (i32 , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | (p2b . slot , (sender , p2b)) }), + input: Tee { + inner: , + }, + }, + Tee { + inner: , }, ), }, + ), + }, + ForEach { + f: stageleft :: runtime_support :: fn1_type_hint :: < & str , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | s | println ! ("{}" , s) }), + input: Source { + source: Iter( + { use crate :: __staged :: cluster :: paxos :: * ; ["Acceptors say hello"] }, + ), + location_kind: Cluster( + 3, + ), }, }, CycleSink { ident: Ident { - sym: cycle_2, + sym: cycle_1, }, location_kind: Cluster( 2, @@ -3944,7 +603,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", ], }, ), @@ -3955,968 +614,378 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Acceptor > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", ], }, ), ), input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , hydroflow_plus_test :: cluster :: paxos :: Ballot) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (p2a , max_ballot) | (p2a . ballot . id , P2b { ballot : p2a . ballot , max_ballot , slot : p2a . slot , value : p2a . value }) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < ((hydroflow_plus_test :: cluster :: paxos :: P1a , hydroflow_plus_test :: cluster :: paxos :: Ballot) , (i32 , std :: collections :: hash_map :: HashMap < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > >)) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((p1a , max_ballot) , (_prev_checkpoint , log)) | (p1a . ballot . id , P1b { ballot : p1a . ballot , max_ballot , accepted : log }) }), input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", - ], - }, + CrossSingleton( + Tee { + inner: : Inspect { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | println ! ("Acceptor received P1a: {:?}" , p1a) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos :: P1a) , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + input: Network { + from_location: Cluster( + 2, ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", - ], - }, + from_key: None, + to_location: Cluster( + 3, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos :: P1a) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& data) . unwrap () . into ()) }", + ], + }, + ), ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& b) . unwrap ()) }", + ], + }, + ), + ), + input: FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > > (__hydroflow_plus_cluster_ids_3) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | ballot_num | P1a { ballot : Ballot { num : ballot_num , id : p_id } } }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Tee { + inner: , + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Tee { + inner: , + }, + }, + ), + }, + }, + }, + }, + }, + }, + }, + Tee { + inner: : Union( + Reduce { + f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), + input: Persist( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | p1a . ballot }), + input: Tee { + inner: , + }, + }, ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , ()) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , ()) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Union( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , u32) , core :: option :: Option < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((slot , (count , entry)) , ballot_num) | if count <= f as u32 { Some (P2a { ballot : Ballot { num : ballot_num , id : p_id , } , slot , value : entry . value , }) } else { None } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, + }, + Persist( + Source { + source: Iter( + { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : ClusterId :: from_raw (0) } } ; [e] }, + ), + location_kind: Cluster( + 3, + ), + }, + ), + ), + }, + ), + Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < (i32 , std :: collections :: hash_map :: HashMap < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (- 1 , HashMap :: new ()) }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (i32 , std :: collections :: hash_map :: HashMap < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > >) , (i32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (prev_checkpoint , log) , (new_checkpoint , p2a) | { if new_checkpoint != - 1 { for slot in * prev_checkpoint .. new_checkpoint { log . remove (& slot) ; } * prev_checkpoint = new_checkpoint ; } else { if p2a . slot > * prev_checkpoint { match log . get (& p2a . slot) { None => { log . insert (p2a . slot , LogValue { ballot : p2a . ballot , value : p2a . value , } ,) ; } Some (prev_p2a) => { if p2a . ballot > prev_p2a . ballot { log . insert (p2a . slot , LogValue { ballot : p2a . ballot , value : p2a . value , } ,) ; } } } ; } } } }), + input: Persist( + Union( + FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , hydroflow_plus_test :: cluster :: paxos :: Ballot) , core :: option :: Option < (i32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (p2a , max_ballot) | if p2a . ballot >= max_ballot { Some ((- 1 , p2a)) } else { None } }), + input: CrossSingleton( + Tee { + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + input: Network { + from_location: Cluster( + 2, + ), + from_key: None, + to_location: Cluster( + 3, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", + ], + }, + ), + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", + ], + }, + ), + ), + input: FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > > (__hydroflow_plus_cluster_ids_3) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , ()) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Union( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , ()) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Union( + FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < ((i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , u32) , core :: option :: Option < hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | ((slot , (count , entry)) , ballot_num) | if count <= f as u32 { Some (P2a { ballot : Ballot { num : ballot_num , id : p_id , } , slot , value : entry . value , }) } else { None } }), + input: CrossSingleton( + Tee { + inner: , }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), + Tee { + inner: , }, ), - ), - }, - }, - ), - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , u32) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (slot , ballot_num) | P2a { ballot : Ballot { num : ballot_num , id : p_id } , slot , value : Default :: default () } }), - input: CrossSingleton( - Difference( - FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: ops :: Range < i32 > > ({ use crate :: __staged :: cluster :: paxos :: * ; | max_slot | 0 .. max_slot }), - input: Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , u32) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | (slot , ballot_num) | P2a { ballot : Ballot { num : ballot_num , id : p_id } , slot , value : Default :: default () } }), + input: CrossSingleton( + Difference( + FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: ops :: Range < i32 > > ({ use crate :: __staged :: cluster :: paxos :: * ; | max_slot | 0 .. max_slot }), input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - }, + inner: , }, }, - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , LogValue { ballot : Ballot { num : 0 , id : 0 } , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_entry , new_entry | { let same_values = new_entry . value == curr_entry . 1 . value ; let higher_ballot = new_entry . ballot > curr_entry . 1 . ballot ; if same_values { curr_entry . 0 += 1 ; } if higher_ballot { curr_entry . 1 . ballot = new_entry . ballot ; if ! same_values { curr_entry . 0 = 1 ; curr_entry . 1 . value = new_entry . value ; } } } }), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , std :: collections :: hash_map :: IntoIter < i32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((_ , p1b) , _) | p1b . accepted . into_iter () }), + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: LogValue < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (slot , _) | slot }), input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, + inner: , }, }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), + Tee { + inner: , }, ), - ), - }, - }, - ), - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: stream :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, + }, + ), + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: stream :: * ; | c | * c == 0 }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: , + }, }, - location_kind: Cluster( - 2, - ), }, }, - }, + ), }, - }, - }, - ), - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (((usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , i32) , u32) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (((index , payload) , next_slot) , ballot_num) | P2a { ballot : Ballot { num : ballot_num , id : p_id } , slot : next_slot + index as i32 , value : payload } }), - input: CrossSingleton( - CrossSingleton( - Enumerate( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 0, - ), - from_key: None, - to_location: Cluster( - 2, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 0, - ), + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (((usize , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , i32) , u32) , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | (((index , payload) , next_slot) , ballot_num) | P2a { ballot : Ballot { num : ballot_num , id : p_id } , slot : next_slot + index as i32 , value : payload } }), + input: CrossSingleton( + CrossSingleton( + Enumerate( + Tee { + inner: , }, + ), + Tee { + inner: , }, + ), + Tee { + inner: , }, - }, + ), }, ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), + input: Tee { + inner: , }, }, ), + }, + }, + }, + }, + }, + Tee { + inner: , + }, + ), + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , (i32 , hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | min_seq | (min_seq , P2a { ballot : Ballot { num : 0 , id : ClusterId :: from_raw (0) } , slot : - 1 , value : Default :: default () }) }), + input: Delta( + Union( + Reduce { + f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new < * curr { * curr = new ; } } }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_sender , seq) | seq }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < ((hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > , i32) , ()) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > , i32) > ({ use hydroflow_plus :: __staged :: stream :: * ; | (d , _signal) | d }), + input: CrossSingleton( Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, + inner: : ReduceKeyed { + f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | curr_seq , seq | { if seq > * curr_seq { * curr_seq = seq ; } } }), + input: Persist( + Network { + from_location: Cluster( + 1, ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, + from_key: None, + to_location: Cluster( + 3, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , i32) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < i32 > (& data) . unwrap () . into ()) }", + ], + }, ), - }, - ), - ), - }, - }, - ), - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < i32 > (& b) . unwrap ()) }", + ], }, - }, + ), ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, + input: FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < i32 , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Acceptor > > > (__hydroflow_plus_cluster_ids_3) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + input: CycleSource { + ident: Ident { + sym: cycle_0, + }, + location_kind: Cluster( + 1, ), }, }, }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | p1a . ballot }), - input: Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | p1a | println ! ("Acceptor received P1a: {:?}" , p1a) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1a) , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 3, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P1a > (& b) . unwrap ()) }", - ], - }, ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: P1a , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_3 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , hydroflow_plus_test :: cluster :: paxos :: P1a > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ballot_num | P1a { ballot : Ballot { num : ballot_num , id : p_id } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , ()) , u32 > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; move | (_ , latest_received_i_am_leader) | { if let Some (latest_received_i_am_leader) = latest_received_i_am_leader { (Instant :: now () . duration_since (* latest_received_i_am_leader)) > Duration :: from_secs (i_am_leader_check_timeout) } else { true } } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) , ()) , (tokio :: time :: Instant , core :: option :: Option < tokio :: time :: Instant >) > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - CrossSingleton( - Source { - source: Stream( - { use hydroflow_plus :: __staged :: location :: * ; let delay = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout_delay_multiplier = 1usize ; let p_id = __hydroflow_plus_cluster_self_id_2 ; Duration :: from_secs ((p_id * i_am_leader_check_timeout_delay_multiplier as u32) . into ()) } ; let interval = { use crate :: __staged :: cluster :: paxos :: * ; let i_am_leader_check_timeout = 1u64 ; Duration :: from_secs (i_am_leader_check_timeout) } ; tokio_stream :: wrappers :: IntervalStream :: new (tokio :: time :: interval_at (tokio :: time :: Instant :: now () + delay , interval)) }, - ), - location_kind: Cluster( - 2, - ), - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < core :: option :: Option < tokio :: time :: Instant > > ({ use crate :: __staged :: cluster :: paxos :: * ; | | None }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < core :: option :: Option < tokio :: time :: Instant > , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | latest , _ | { * latest = Some (Instant :: now ()) ; } }), - input: Persist( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - }, - }, - }, - ), - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - }, - ), - }, - }, - }, - }, - }, - ), + }, + }, + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < bool , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | _u | () }), + input: FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received == f + 1 { Some (true) } else { None } }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > , i32) , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: , }, }, }, }, - }, + ), }, }, }, - }, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 3, - ), - }, - ), + Persist( + Source { + source: Iter( + { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; - 1 } ; [e] }, + ), + location_kind: Cluster( + 3, + ), + }, + ), + ), + ), + }, ), - }, + ), + }, + ), + }, + }, + }, + CycleSink { + ident: Ident { + sym: cycle_2, + }, + location_kind: Cluster( + 2, + ), + input: Network { + from_location: Cluster( + 3, + ), + from_key: None, + to_location: Cluster( + 2, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& data) . unwrap () . into ()) }", + ], + }, + ), + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Acceptor > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > > (& b) . unwrap ()) }", + ], + }, + ), + ), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: P2a < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload > , hydroflow_plus_test :: cluster :: paxos :: Ballot) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (p2a , max_ballot) | (p2a . ballot . id , P2b { ballot : p2a . ballot , max_ballot , slot : p2a . slot , value : p2a . value }) }), + input: CrossSingleton( + Tee { + inner: , + }, + Tee { + inner: , }, ), }, @@ -4936,892 +1005,140 @@ expression: built.ir() f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , bool > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , highest_seq) | sorted_payload . seq > * highest_seq }), input: CrossSingleton( Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], + inner: : Sort( + Union( + Tee { + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + input: Network { + from_location: Cluster( + 2, + ), + from_key: None, + to_location: Cluster( + 1, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", + ], + }, + ), + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", + ], + }, + ), + ), + input: FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > > > (__hydroflow_plus_cluster_ids_1) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), + input: AntiJoin( + Tee { + inner: , }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, + CycleSource { + ident: Ident { + sym: cycle_5, + }, + location_kind: Cluster( + 2, ), }, - }, + ), }, }, }, }, }, + }, + CycleSource { + ident: Ident { + sym: cycle_1, + }, + location_kind: Cluster( + 1, + ), + }, + ), + ), + }, + Tee { + inner: : Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | - 1 }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | filled_slot , (sorted_payload , highest_seq) | { let next_slot = std :: cmp :: max (* filled_slot , highest_seq) ; * filled_slot = if sorted_payload . seq == next_slot + 1 { sorted_payload . seq } else { * filled_slot } ; } }), + input: CrossSingleton( + Tee { + inner: , + }, + Union( CycleSource { ident: Ident { - sym: cycle_1, + sym: cycle_2, }, location_kind: Cluster( 1, ), }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | - 1 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | filled_slot , (sorted_payload , highest_seq) | { let next_slot = std :: cmp :: max (* filled_slot , highest_seq) ; * filled_slot = if sorted_payload . seq == next_slot + 1 { sorted_payload . seq } else { * filled_slot } ; } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Union( - CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 1, - ), - }, - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos_bench :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - }, - ), - }, - }, - ), - }, - CycleSink { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 1, - ), - input: DeferTick( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (_kv_store , highest_seq) | highest_seq }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | (HashMap :: < u32 , String > :: new () , - 1) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | state , payload | { let kv_store = & mut state . 0 ; let last_seq = & mut state . 1 ; kv_store . insert (payload . key , payload . value) ; debug_assert ! (payload . seq == * last_seq + 1 , "Hole in log between seq {} and {}" , * last_seq , payload . seq) ; * last_seq = payload . seq ; } }), - input: Persist( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , _) | { sorted_payload } }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , bool > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , highest_seq) | sorted_payload . seq <= * highest_seq }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | - 1 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | filled_slot , (sorted_payload , highest_seq) | { let next_slot = std :: cmp :: max (* filled_slot , highest_seq) ; * filled_slot = if sorted_payload . seq == next_slot + 1 { sorted_payload . seq } else { * filled_slot } ; } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Union( - CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 1, - ), - }, - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos_bench :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - }, - ), - }, + Source { + source: Iter( + { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos_bench :: * ; - 1 } ; [e] }, + ), + location_kind: Cluster( + 1, + ), }, - }, - }, - ), + ), + ), + }, }, - }, + ), }, }, ), }, CycleSink { ident: Ident { - sym: cycle_3, + sym: cycle_2, }, location_kind: Cluster( 1, ), input: DeferTick( Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , i32) , core :: option :: Option < i32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let checkpoint_frequency = 1usize ; move | (max_checkpointed_seq , new_highest_seq) | if new_highest_seq - max_checkpointed_seq >= checkpoint_frequency as i32 { Some (new_highest_seq) } else { None } }), - input: CrossSingleton( - Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - CycleSource { - ident: Ident { - sym: cycle_3, + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (_kv_store , highest_seq) | highest_seq }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | (HashMap :: < u32 , String > :: new () , - 1) }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | state , payload | { let kv_store = & mut state . 0 ; let last_seq = & mut state . 1 ; kv_store . insert (payload . key , payload . value) ; debug_assert ! (payload . seq == * last_seq + 1 , "Hole in log between seq {} and {}" , * last_seq , payload . seq) ; * last_seq = payload . seq ; } }), + input: Persist( + Tee { + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , _) | { sorted_payload } }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , bool > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , highest_seq) | sorted_payload . seq <= * highest_seq }), + input: CrossSingleton( + Tee { + inner: , + }, + Tee { + inner: , }, - location_kind: Cluster( - 1, - ), - }, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos_bench :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 1, ), }, - ), - ), - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (_kv_store , highest_seq) | highest_seq }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | (HashMap :: < u32 , String > :: new () , - 1) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | state , payload | { let kv_store = & mut state . 0 ; let last_seq = & mut state . 1 ; kv_store . insert (payload . key , payload . value) ; debug_assert ! (payload . seq == * last_seq + 1 , "Hole in log between seq {} and {}" , * last_seq , payload . seq) ; * last_seq = payload . seq ; } }), - input: Persist( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , _) | { sorted_payload } }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , bool > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , highest_seq) | sorted_payload . seq <= * highest_seq }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | - 1 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | filled_slot , (sorted_payload , highest_seq) | { let next_slot = std :: cmp :: max (* filled_slot , highest_seq) ; * filled_slot = if sorted_payload . seq == next_slot + 1 { sorted_payload . seq } else { * filled_slot } ; } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Union( - CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 1, - ), - }, - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos_bench :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, }, }, ), @@ -5832,14 +1149,14 @@ expression: built.ir() }, CycleSink { ident: Ident { - sym: cycle_0, + sym: cycle_3, }, location_kind: Cluster( 1, ), - input: Tee { - inner: RefCell { - value: FilterMap { + input: DeferTick( + Tee { + inner: : FilterMap { f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , i32) , core :: option :: Option < i32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let checkpoint_frequency = 1usize ; move | (max_checkpointed_seq , new_highest_seq) | if new_highest_seq - max_checkpointed_seq >= checkpoint_frequency as i32 { Some (new_highest_seq) } else { None } }), input: CrossSingleton( Union( @@ -5868,295 +1185,22 @@ expression: built.ir() ), ), Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (_kv_store , highest_seq) | highest_seq }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | (HashMap :: < u32 , String > :: new () , - 1) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (std :: collections :: hash_map :: HashMap < u32 , std :: string :: String > , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | state , payload | { let kv_store = & mut state . 0 ; let last_seq = & mut state . 1 ; kv_store . insert (payload . key , payload . value) ; debug_assert ! (payload . seq == * last_seq + 1 , "Hole in log between seq {} and {}" , * last_seq , payload . seq) ; * last_seq = payload . seq ; } }), - input: Persist( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , _) | { sorted_payload } }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , bool > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sorted_payload , highest_seq) | sorted_payload . seq <= * highest_seq }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < i32 > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | - 1 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < i32 , (hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , i32) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | filled_slot , (sorted_payload , highest_seq) | { let next_slot = std :: cmp :: max (* filled_slot , highest_seq) ; * filled_slot = if sorted_payload . seq == next_slot + 1 { sorted_payload . seq } else { * filled_slot } ; } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Sort( - Union( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - Union( - CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 1, - ), - }, - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos_bench :: * ; - 1 } ; [e] }, - ), - location_kind: Cluster( - 1, - ), - }, - ), - ), - }, - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, + inner: , }, ), }, }, + ), + }, + CycleSink { + ident: Ident { + sym: cycle_0, + }, + location_kind: Cluster( + 1, + ), + input: Tee { + inner: , }, }, CycleSink { @@ -6169,316 +1213,65 @@ expression: built.ir() input: DeferTick( AntiJoin( Tee { - inner: RefCell { - value: Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , u32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), - input: Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), + inner: : Union( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica >) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), + input: Network { + from_location: Cluster( + 1, + ), + from_key: None, + to_location: Cluster( + 0, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", + ], + }, ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (payload . value . parse :: < u32 > () . unwrap () , payload) }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", + ], }, + ), + ), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Client > , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (ClusterId :: from_raw (payload . value . parse :: < u32 > () . unwrap ()) , payload) }), + input: Tee { + inner: , }, }, }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 0, - ), + }, + CycleSource { + ident: Ident { + sym: cycle_1, }, - ), - }, - }, - Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , usize) , core :: option :: Option < u32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let f = 1usize ; move | (key , count) | { if count == f + 1 { Some (key) } else { None } } }), - input: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | 0 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | curr_count , _sender | { * curr_count += 1 ; } }), - input: Tee { - inner: RefCell { - value: Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , u32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), - input: Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (payload . value . parse :: < u32 > () . unwrap () , payload) }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 0, - ), - }, - ), - }, - }, + location_kind: Cluster( + 0, + ), + }, + ), + }, + Tee { + inner: : FilterMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , usize) , core :: option :: Option < u32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let f = 1usize ; move | (key , count) | { if count == f + 1 { Some (key) } else { None } } }), + input: FoldKeyed { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | 0 }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Replica > , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | curr_count , _sender | { * curr_count += 1 ; } }), + input: Tee { + inner: , }, }, }, @@ -6499,15 +1292,13 @@ expression: built.ir() input: Union( Union( Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 0, - ), + inner: : CycleSource { + ident: Ident { + sym: cycle_2, }, + location_kind: Cluster( + 0, + ), }, }, FlatMap { @@ -6515,464 +1306,93 @@ expression: built.ir() input: Map { f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: time :: SystemTime > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | _ | SystemTime :: now () }), input: Tee { - inner: RefCell { - value: Delta( - Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | ballot | println ! ("Client notified that leader was elected: {:?}" , ballot) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_0 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , u32) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (_is_leader , ballot_num) | Ballot { num : ballot_num , id : p_id } }), + inner: : Delta( + Tee { + inner: : Reduce { + f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), + input: Persist( + Inspect { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | ballot | println ! ("Client notified that leader was elected: {:?}" , ballot) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos :: Ballot) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), + input: Network { + from_location: Cluster( + 2, + ), + from_key: None, + to_location: Cluster( + 0, + ), + to_key: None, + serialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , hydroflow_plus_test :: cluster :: paxos :: Ballot) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& data) . unwrap () . into ()) }", + ], + }, + ), + ), + instantiate_fn: , + deserialize_pipeline: Some( + Operator( + Operator { + path: "map", + args: [ + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& b) . unwrap ()) }", + ], + }, + ), + ), + input: FlatMap { + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: slice :: Iter < hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Client > > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < hydroflow_plus_test :: cluster :: paxos_bench :: Client > > > (__hydroflow_plus_cluster_ids_0) } ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , u32) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos :: Proposer > :: from_raw (__hydroflow_plus_cluster_self_id_2) ; move | (_is_leader , ballot_num) | Ballot { num : ballot_num , id : p_id } }), + input: CrossSingleton( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), input: CrossSingleton( + Tee { + inner: , + }, Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), + input: Filter { + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), + input: Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: , }, }, - ), - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), }, }, ), }, - }, + Tee { + inner: , + }, + ), }, }, }, - ), + }, }, - }, + ), }, - ), - }, + }, + ), }, }, }, ), Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , (usize , std :: time :: SystemTime) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | key | (key as usize , SystemTime :: now ()) }), - input: Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , usize) , core :: option :: Option < u32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let f = 1usize ; move | (key , count) | { if count == f + 1 { Some (key) } else { None } } }), - input: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | 0 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | curr_count , _sender | { * curr_count += 1 ; } }), - input: Tee { - inner: RefCell { - value: Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , u32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), - input: Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (payload . value . parse :: < u32 > () . unwrap () , payload) }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 0, - ), - }, - ), - }, - }, - }, - }, - }, - }, + inner: : Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , (usize , std :: time :: SystemTime) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | key | (key as usize , SystemTime :: now ()) }), + input: Tee { + inner: , }, }, }, @@ -6985,405 +1405,58 @@ expression: built.ir() input: CrossSingleton( CrossSingleton( Tee { - inner: RefCell { - value: Source { - source: Interval( - { use crate :: __staged :: cluster :: paxos_bench :: * ; Duration :: from_secs (1) }, - ), - location_kind: Cluster( - 0, - ), - }, + inner: : Source { + source: Interval( + { use crate :: __staged :: cluster :: paxos_bench :: * ; Duration :: from_secs (1) }, + ), + location_kind: Cluster( + 0, + ), }, }, Fold { init: stageleft :: runtime_support :: fn0_type_hint :: < (std :: rc :: Rc < core :: cell :: RefCell < std :: vec :: Vec < u128 > > > , usize , bool) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let median_latency_window_size = 1usize ; move | | (Rc :: new (RefCell :: new (Vec :: < u128 > :: with_capacity (median_latency_window_size))) , 0usize , false) }), acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (std :: rc :: Rc < core :: cell :: RefCell < std :: vec :: Vec < u128 > > > , usize , bool) , core :: option :: Option < u128 > , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let median_latency_window_size = 1usize ; move | (latencies , write_index , has_any_value) , latency | { let mut latencies_mut = latencies . borrow_mut () ; if let Some (latency) = latency { if let Some (prev_latency) = latencies_mut . get_mut (* write_index) { * prev_latency = latency ; } else { latencies_mut . push (latency) ; } * has_any_value = true ; * write_index += 1 ; if * write_index == median_latency_window_size { * write_index = 0 ; } } else { latencies_mut . clear () ; * write_index = 0 ; * has_any_value = false ; } } }), input: Persist( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , (std :: time :: SystemTime , std :: time :: SystemTime)) , core :: option :: Option < u128 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (_virtual_id , (prev_time , curr_time)) | Some (curr_time . duration_since (prev_time) . unwrap () . as_micros ()) }), - input: Join( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 0, - ), - }, - }, - }, - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < u32 , (usize , std :: time :: SystemTime) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | key | (key as usize , SystemTime :: now ()) }), - input: Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , usize) , core :: option :: Option < u32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let f = 1usize ; move | (key , count) | { if count == f + 1 { Some (key) } else { None } } }), - input: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | 0 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | curr_count , _sender | { * curr_count += 1 ; } }), - input: Tee { - inner: RefCell { - value: Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , u32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), - input: Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (payload . value . parse :: < u32 > () . unwrap () , payload) }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 0, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - ), - }, - DeferTick( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < () , core :: option :: Option < u128 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | _ | None }), - input: Tee { - inner: RefCell { - value: Source { - source: Interval( - { use crate :: __staged :: cluster :: paxos_bench :: * ; Duration :: from_secs (1) }, - ), - location_kind: Cluster( - 0, - ), - }, - }, - }, - }, - ), - ), - ), - }, - ), - Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , i32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | (0 , 0) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , i32) , (usize , bool) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (total , num_ticks) , (batch_size , reset) | { if reset { * total = 0 ; * num_ticks = 0 ; } else { * total += batch_size as u32 ; * num_ticks += 1 ; } } }), - input: Persist( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , (usize , bool) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | batch_size | (batch_size , false) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , ()) , usize > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , usize) , core :: option :: Option < u32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let f = 1usize ; move | (key , count) | { if count == f + 1 { Some (key) } else { None } } }), - input: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | 0 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | curr_count , _sender | { * curr_count += 1 ; } }), - input: Tee { - inner: RefCell { - value: Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , u32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), - input: Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (payload . value . parse :: < u32 > () . unwrap () , payload) }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 0, - ), - }, - ), - }, - }, - }, - }, - }, + Union( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , (std :: time :: SystemTime , std :: time :: SystemTime)) , core :: option :: Option < u128 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (_virtual_id , (prev_time , curr_time)) | Some (curr_time . duration_since (prev_time) . unwrap () . as_micros ()) }), + input: Join( + Tee { + inner: , + }, + Tee { + inner: , + }, + ), + }, + DeferTick( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < () , core :: option :: Option < u128 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | _ | None }), + input: Tee { + inner: , + }, + }, + ), + ), + ), + }, + ), + Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < (u32 , i32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | (0 , 0) }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (u32 , i32) , (usize , bool) , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (total , num_ticks) , (batch_size , reset) | { if reset { * total = 0 ; * num_ticks = 0 ; } else { * total += batch_size as u32 ; * num_ticks += 1 ; } } }), + input: Persist( + Union( + Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < usize , (usize , bool) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | batch_size | (batch_size , false) }), + input: Map { + f: stageleft :: runtime_support :: fn1_type_hint :: < (usize , ()) , usize > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), + input: CrossSingleton( + Fold { + init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), + acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), + input: Tee { + inner: , }, }, Map { @@ -7394,16 +1467,7 @@ expression: built.ir() init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , () , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), input: Tee { - inner: RefCell { - value: Source { - source: Interval( - { use crate :: __staged :: cluster :: paxos_bench :: * ; Duration :: from_secs (1) }, - ), - location_kind: Cluster( - 0, - ), - }, - }, + inner: , }, }, }, @@ -7415,16 +1479,7 @@ expression: built.ir() Map { f: stageleft :: runtime_support :: fn1_type_hint :: < () , (usize , bool) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | _ | (0 , true) }), input: Tee { - inner: RefCell { - value: Source { - source: Interval( - { use crate :: __staged :: cluster :: paxos_bench :: * ; Duration :: from_secs (1) }, - ), - location_kind: Cluster( - 0, - ), - }, - }, + inner: , }, }, ), @@ -7442,745 +1497,19 @@ expression: built.ir() ), input: Union( FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: ops :: Range < usize > , _ > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let c_id = __hydroflow_plus_cluster_self_id_0 ; let num_clients_per_node = 1usize ; move | leader_ballot | (0 .. num_clients_per_node) . map (move | i | (leader_ballot . leader_id () , ClientPayload { key : i as u32 , value : c_id . to_string () })) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: ops :: Range < usize > , _ > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let c_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos_bench :: Client > :: from_raw (__hydroflow_plus_cluster_self_id_0) ; let num_clients_per_node = 1usize ; move | leader_ballot | (0 .. num_clients_per_node) . map (move | i | (leader_ballot . leader_id () , ClientPayload { key : i as u32 , value : c_id . raw_id . to_string () })) }), input: Tee { - inner: RefCell { - value: Delta( - Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | ballot | println ! ("Client notified that leader was elected: {:?}" , ballot) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_0 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , u32) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (_is_leader , ballot_num) | Ballot { num : ballot_num , id : p_id } }), - input: CrossSingleton( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - ), - }, - }, - }, - ), - }, + inner: , }, }, Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot) , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let c_id = __hydroflow_plus_cluster_self_id_0 ; move | (key , leader_ballot) | (leader_ballot . leader_id () , ClientPayload { key , value : c_id . to_string () }) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot) , (hydroflow_plus :: location :: ClusterId < hydroflow_plus_test :: cluster :: paxos :: Proposer > , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let c_id = hydroflow_plus :: ClusterId :: < hydroflow_plus_test :: cluster :: paxos_bench :: Client > :: from_raw (__hydroflow_plus_cluster_self_id_0) ; move | (key , leader_ballot) | (leader_ballot . leader_id () , ClientPayload { key , value : c_id . raw_id . to_string () }) }), input: CrossSingleton( Tee { - inner: RefCell { - value: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , usize) , core :: option :: Option < u32 > > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; let f = 1usize ; move | (key , count) | { if count == f + 1 { Some (key) } else { None } } }), - input: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | | 0 }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | curr_count , _sender | { * curr_count += 1 ; } }), - input: Tee { - inner: RefCell { - value: Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , (u32 , u32) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (sender , replica_payload) | (replica_payload . key , sender) }), - input: Network { - from_location: Cluster( - 1, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | payload | (payload . value . parse :: < u32 > () . unwrap () , payload) }), - input: Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 1, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_1 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) , hydroflow_plus_test :: cluster :: paxos_bench :: ReplicaPayload > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | (slot , data) | ReplicaPayload { seq : slot , key : data . key , value : data . value } }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , (i32 , hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload) > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_slot , (_count , p2b)) | (p2b . slot , p2b . value) }), - input: AntiJoin( - Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (i32 , (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | (_slot , (count , _p2b)) | * count > f }), - input: Tee { - inner: RefCell { - value: FoldKeyed { - init: stageleft :: runtime_support :: fn0_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) > ({ use crate :: __staged :: cluster :: paxos :: * ; | | (0 , P2b { ballot : Ballot { num : 0 , id : 0 } , max_ballot : Ballot { num : 0 , id : 0 } , slot : 0 , value : Default :: default () }) }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < (usize , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | accum , (_sender , p2b) | { accum . 0 += 1 ; accum . 1 = p2b ; } }), - input: FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , core :: option :: Option < (i32 , (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >)) > > ({ use crate :: __staged :: cluster :: paxos :: * ; | (sender , p2b) | if p2b . ballot == p2b . max_ballot { Some ((p2b . slot , (sender , p2b))) } else { None } }), - input: Tee { - inner: RefCell { - value: Union( - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_6, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_5, - }, - location_kind: Cluster( - 2, - ), - }, - ), - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 0, - ), - }, - ), - }, - }, - }, - }, - }, + inner: , }, Tee { - inner: RefCell { - value: Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use crate :: __staged :: cluster :: paxos_bench :: * ; | ballot | println ! ("Client notified that leader was elected: {:?}" , ballot) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: Ballot) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use hydroflow_plus :: __staged :: stream :: * ; | (_ , b) | b }), - input: Network { - from_location: Cluster( - 2, - ), - from_key: None, - to_location: Cluster( - 0, - ), - to_key: None, - serialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& data) . unwrap () . into ()) }", - ], - }, - ), - ), - instantiate_fn: , - deserialize_pipeline: Some( - Operator( - Operator { - path: "map", - args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < hydroflow_plus_test :: cluster :: paxos :: Ballot > (& b) . unwrap ()) }", - ], - }, - ), - ), - input: FlatMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , std :: iter :: Map < std :: slice :: Iter < u32 > , _ > > ({ use hydroflow_plus :: __staged :: stream :: * ; let ids = __hydroflow_plus_cluster_ids_0 ; | b | ids . iter () . map (move | id | (:: std :: clone :: Clone :: clone (id) , :: std :: clone :: Clone :: clone (& b))) }), - input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , u32) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (_is_leader , ballot_num) | Ballot { num : ballot_num , id : p_id } }), - input: CrossSingleton( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (bool , ()) , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | (d , _signal) | d }), - input: CrossSingleton( - FilterMap { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , core :: option :: Option < bool > > ({ use crate :: __staged :: cluster :: paxos :: * ; let f = 1usize ; move | num_received | if num_received > f { Some (true) } else { None } }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , u32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Unique( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , u32 > ({ use crate :: __staged :: cluster :: paxos :: * ; | ((sender , _p1b) , _ballot_num) | { sender } }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < ((u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | ((_sender , p1b) , ballot_num) | p1b . ballot == Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Persist( - Tee { - inner: RefCell { - value: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , () > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | println ! ("Proposer received P1b: {:?}" , p1b) }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Tee { - inner: RefCell { - value: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus_test :: cluster :: paxos :: Ballot , u32) , bool > ({ use crate :: __staged :: cluster :: paxos :: * ; let p_id = __hydroflow_plus_cluster_self_id_2 ; move | (received_max_ballot , ballot_num) | * received_max_ballot <= Ballot { num : * ballot_num , id : p_id } }), - input: CrossSingleton( - Tee { - inner: RefCell { - value: Union( - Reduce { - f: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < hydroflow_plus_test :: cluster :: paxos :: Ballot , hydroflow_plus_test :: cluster :: paxos :: Ballot , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | curr , new | { if new > * curr { * curr = new ; } } }), - input: Persist( - Union( - Union( - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P1b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p1b) | p1b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_1, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , hydroflow_plus_test :: cluster :: paxos :: P2b < hydroflow_plus_test :: cluster :: paxos_bench :: ClientPayload >) , hydroflow_plus_test :: cluster :: paxos :: Ballot > ({ use crate :: __staged :: cluster :: paxos :: * ; | (_ , p2b) | p2b . max_ballot }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_2, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - ), - Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_0, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - ), - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; Ballot { num : 0 , id : 0 } } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - ), - }, - }, - }, - Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < usize , () > ({ use hydroflow_plus :: __staged :: singleton :: * ; | _u | () }), - input: Filter { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < usize , bool > ({ use hydroflow_plus :: __staged :: singleton :: * ; | c | * c == 0 }), - input: Fold { - init: stageleft :: runtime_support :: fn0_type_hint :: < usize > ({ use hydroflow_plus :: __staged :: stream :: * ; | | 0usize }), - acc: stageleft :: runtime_support :: fn2_borrow_mut_type_hint :: < usize , i32 , () > ({ use hydroflow_plus :: __staged :: stream :: * ; | count , _ | * count += 1 }), - input: Tee { - inner: RefCell { - value: CycleSource { - ident: Ident { - sym: cycle_4, - }, - location_kind: Cluster( - 2, - ), - }, - }, - }, - }, - }, - }, - ), - }, - Tee { - inner: RefCell { - value: Union( - CycleSource { - ident: Ident { - sym: cycle_3, - }, - location_kind: Cluster( - 2, - ), - }, - Persist( - Source { - source: Iter( - { use hydroflow_plus :: __staged :: location :: * ; let e = { use crate :: __staged :: cluster :: paxos :: * ; 0 } ; [e] }, - ), - location_kind: Cluster( - 2, - ), - }, - ), - ), - }, - }, - ), - }, - }, - }, - }, - }, - ), - }, - }, + inner: , }, ), }, diff --git a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__simple_cluster__tests__simple_cluster.snap b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__simple_cluster__tests__simple_cluster.snap index 1889a09ef06e..8fd05b1df972 100644 --- a/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__simple_cluster__tests__simple_cluster.snap +++ b/hydroflow_plus_test/src/cluster/snapshots/hydroflow_plus_test__cluster__simple_cluster__tests__simple_cluster.snap @@ -4,7 +4,7 @@ expression: built.ir() --- [ ForEach { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , (u32 , i32)) , () > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; | (id , d) | println ! ("node received: ({}, {:?})" , id , d) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < () > , (hydroflow_plus :: location :: ClusterId < () > , i32)) , () > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; | (id , d) | println ! ("node received: ({}, {:?})" , id , d) }), input: Network { from_location: Cluster( 1, @@ -19,7 +19,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| data | { hydroflow_plus :: runtime_support :: bincode :: serialize :: < (u32 , i32) > (& data) . unwrap () . into () }", + "| data | { hydroflow_plus :: runtime_support :: bincode :: serialize :: < (hydroflow_plus :: location :: ClusterId < () > , i32) > (& data) . unwrap () . into () }", ], }, ), @@ -30,13 +30,13 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { let (id , b) = res . unwrap () ; (id , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (u32 , i32) > (& b) . unwrap ()) }", + "| res | { let (id , b) = res . unwrap () ; (hydroflow_plus :: ClusterId :: < () > :: from_raw (id) , hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (hydroflow_plus :: location :: ClusterId < () > , i32) > (& b) . unwrap ()) }", ], }, ), ), input: Inspect { - f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (u32 , i32) , () > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; let cluster_self_id = __hydroflow_plus_cluster_self_id_1 ; move | n | println ! ("cluster received: {:?} (self cluster id: {})" , n , cluster_self_id) }), + f: stageleft :: runtime_support :: fn1_borrow_type_hint :: < (hydroflow_plus :: location :: ClusterId < () > , i32) , () > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; let cluster_self_id = hydroflow_plus :: ClusterId :: < () > :: from_raw (__hydroflow_plus_cluster_self_id_1) ; move | n | println ! ("cluster received: {:?} (self cluster id: {})" , n , cluster_self_id) }), input: Network { from_location: Process( 0, @@ -51,7 +51,7 @@ expression: built.ir() Operator { path: "map", args: [ - "| (id , data) | { (id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < (u32 , i32) > (& data) . unwrap () . into ()) }", + "| (id , data) : (hydroflow_plus :: ClusterId < _ > , (hydroflow_plus :: location :: ClusterId < () > , i32)) | { (id . raw_id , hydroflow_plus :: runtime_support :: bincode :: serialize :: < (hydroflow_plus :: location :: ClusterId < () > , i32) > (& data) . unwrap () . into ()) }", ], }, ), @@ -62,21 +62,21 @@ expression: built.ir() Operator { path: "map", args: [ - "| res | { hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (u32 , i32) > (& res . unwrap ()) . unwrap () }", + "| res | { hydroflow_plus :: runtime_support :: bincode :: deserialize :: < (hydroflow_plus :: location :: ClusterId < () > , i32) > (& res . unwrap ()) . unwrap () }", ], }, ), ), input: Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < (u32 , i32) , (u32 , (u32 , i32)) > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; | (id , n) | (id , (id , n)) }), + f: stageleft :: runtime_support :: fn1_type_hint :: < (hydroflow_plus :: location :: ClusterId < () > , i32) , (hydroflow_plus :: location :: ClusterId < () > , (hydroflow_plus :: location :: ClusterId < () > , i32)) > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; | (id , n) | (id , (id , n)) }), input: Delta( CrossProduct( Persist( Map { - f: stageleft :: runtime_support :: fn1_type_hint :: < & u32 , u32 > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; | & id | id }), + f: stageleft :: runtime_support :: fn1_type_hint :: < & hydroflow_plus :: location :: ClusterId < () > , hydroflow_plus :: location :: ClusterId < () > > ({ use crate :: __staged :: cluster :: simple_cluster :: * ; | & id | id }), input: Source { source: Iter( - __hydroflow_plus_cluster_ids_1, + unsafe { :: std :: mem :: transmute :: < _ , & :: std :: vec :: Vec < hydroflow_plus :: ClusterId < () > > > (__hydroflow_plus_cluster_ids_1) }, ), location_kind: Process( 0, diff --git a/hydroflow_plus_test/src/cluster/two_pc.rs b/hydroflow_plus_test/src/cluster/two_pc.rs new file mode 100644 index 000000000000..42f944cb419f --- /dev/null +++ b/hydroflow_plus_test/src/cluster/two_pc.rs @@ -0,0 +1,93 @@ +use hydroflow_plus::*; +use stageleft::*; + +// if the variable start with p, that means current work is at the participant side. if start with c, at coordinator side. +// + +pub struct Participants {} + +pub struct Coordinator {} + +pub struct Client {} + +pub fn two_pc<'a>( + flow: &FlowBuilder<'a>, + num_participants: u32, +) -> ( + Process<'a, Coordinator>, + Cluster<'a, Participants>, + Process<'a, Client>, +) { + // Assume single client. + let client = flow.process::(); + + // Assume single coordinator. + let coordinator = flow.process::(); + + // Assume 3 participants. + let participants = flow.cluster::(); + + // assume 3 transactions are generated from 0 to 3 + let client_transaction = client.source_iter(q!(0..3)); + + let c_receive_client_transactions = client_transaction.send_bincode(&coordinator); + c_receive_client_transactions + .clone() + .inspect(q!(|t| println!( + "receive transaction {}, ready to broadcast", + t + ))); + + // broadcast prepare message to participants. + let p_receive_prepare = c_receive_client_transactions.broadcast_bincode(&participants); + + // assume all participants reply commit + let p_ready_to_commit = p_receive_prepare.map(q!(|t| (t, String::from("commit")))); + let c_received_reply = p_ready_to_commit.send_bincode(&coordinator); + // c_received_reply.clone().inspect(q!(|(id, (t, reply))| println!("participant {id} said {reply} for transaction {t}"))); + + // collect votes from participant. + // aborted transactions. + let c_participant_voted_abort = c_received_reply + .clone() + .filter(q!(|(_id, (_t, reply))| reply == "abort")) + .map(q!(|(id, (t, _reply))| (t, id))); + let p_receive_abort = c_participant_voted_abort.broadcast_bincode(&participants); + p_receive_abort.clone().inspect(q!(|(t, id)| println!( + "{} vote abort for transaction {}", + id, t + ))); + let c_receive_ack = p_receive_abort.send_bincode(&coordinator); + c_receive_ack.for_each(q!(|(id, (t, _))| println!( + "Coordinator receive participant {} abort for transaction {}", + id, t + ))); + + // committed transactions + let c_participant_voted_commit = c_received_reply + .filter(q!(|(_id, (_t, reply))| reply == "commit")) + .map(q!(|(id, (t, _reply))| (t, id))) + // fold_keyed: 1 input stream of type (K, V1), 1 output stream of type (K, V2). + // The output will have one tuple for each distinct K, with an accumulated value of type V2. + .tick_batch().fold_keyed(q!(|| 0), q!(|old: &mut u32, _| *old += 1)).filter_map(q!(move |(t, count)| { + // here I set the participant to 3. If want more or less participant, fix line 26 of examples/broadcast.rs + if count == num_participants { + Some(t) + } else { + None + } + })); + + // broadcast commit transactions to participants. + let p_receive_commit = c_participant_voted_commit + .all_ticks() + .broadcast_bincode(&participants); + // p_receive_commit.clone().for_each(q!(|t| println!("commit for transaction {}", t))); + + let c_receive_ack = p_receive_commit.send_bincode(&coordinator); + c_receive_ack.for_each(q!(|(id, t)| println!( + "receive participant {} commit for transaction {}", + id, t + ))); + (coordinator, participants, client) +} diff --git a/lattices/Cargo.toml b/lattices/Cargo.toml index b4daacad7ee7..7684d2ca3cfb 100644 --- a/lattices/Cargo.toml +++ b/lattices/Cargo.toml @@ -19,6 +19,9 @@ cc-traits = "2.0.0" sealed = "0.5.0" serde = { version = "1.0.197", features = ["derive"], optional = true } lattices_macro = { path = "../lattices_macro", version = "^0.5.6" } +ref-cast = "1.0.23" +variadics = { path = "../variadics", version = "^0.0.6" } +variadics_macro = { path = "../variadics_macro", version = "^0.5.5" } [dev-dependencies] trybuild = "1.0.0" diff --git a/lattices/src/collections.rs b/lattices/src/collections.rs index 13494e6fe915..42bc8ec24cf8 100644 --- a/lattices/src/collections.rs +++ b/lattices/src/collections.rs @@ -84,7 +84,8 @@ impl Len for VecSet { } } impl CollectionRef for VecSet { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -103,7 +104,8 @@ where } } impl CollectionMut for VecSet { - type ItemMut<'a> = &'a mut Self::Item + type ItemMut<'a> + = &'a mut Self::Item where Self: 'a; @@ -119,7 +121,8 @@ where } } impl Iter for VecSet { - type Iter<'a> = std::slice::Iter<'a, T> + type Iter<'a> + = std::slice::Iter<'a, T> where Self: 'a; @@ -128,7 +131,8 @@ impl Iter for VecSet { } } impl IterMut for VecSet { - type IterMut<'a> = std::slice::IterMut<'a, T> + type IterMut<'a> + = std::slice::IterMut<'a, T> where Self: 'a; @@ -176,7 +180,8 @@ impl Len for VecMap { } } impl CollectionRef for VecMap { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -198,7 +203,8 @@ where } } impl CollectionMut for VecMap { - type ItemMut<'a> = &'a mut Self::Item + type ItemMut<'a> + = &'a mut Self::Item where Self: 'a; @@ -220,7 +226,8 @@ impl Keyed for VecMap { type Key = K; } impl KeyedRef for VecMap { - type KeyRef<'a> = &'a Self::Key + type KeyRef<'a> + = &'a Self::Key where Self: 'a; @@ -254,18 +261,20 @@ impl SimpleKeyedRef for VecMap { simple_keyed_ref!(); } impl MapIter for VecMap { - type Iter<'a> = std::iter::Zip, std::slice::Iter<'a, V>> - where - Self: 'a; + type Iter<'a> + = std::iter::Zip, std::slice::Iter<'a, V>> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.keys.iter().zip(self.vals.iter()) } } impl MapIterMut for VecMap { - type IterMut<'a> = std::iter::Zip, std::slice::IterMut<'a, V>> - where - Self: 'a; + type IterMut<'a> + = std::iter::Zip, std::slice::IterMut<'a, V>> + where + Self: 'a; fn iter_mut(&mut self) -> Self::IterMut<'_> { self.keys.iter().zip(self.vals.iter_mut()) @@ -307,7 +316,10 @@ impl Collection for EmptySet { } impl CollectionRef for EmptySet { - type ItemRef<'a> = &'a Self::Item where Self::Item: 'a; + type ItemRef<'a> + = &'a Self::Item + where + Self::Item: 'a; covariant_item_ref!(); } @@ -328,7 +340,10 @@ impl Len for EmptySet { } impl Iter for EmptySet { - type Iter<'a> = std::iter::Empty<&'a T> where T: 'a; + type Iter<'a> + = std::iter::Empty<&'a T> + where + T: 'a; fn iter(&self) -> Self::Iter<'_> { std::iter::empty() @@ -371,7 +386,8 @@ impl Len for SingletonSet { } } impl CollectionRef for SingletonSet { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -390,7 +406,8 @@ where } } impl CollectionMut for SingletonSet { - type ItemMut<'a> = &'a mut T + type ItemMut<'a> + = &'a mut T where Self: 'a; @@ -406,16 +423,18 @@ where } } impl Iter for SingletonSet { - type Iter<'a> = std::iter::Once<&'a T> - where - Self: 'a; + type Iter<'a> + = std::iter::Once<&'a T> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { std::iter::once(&self.0) } } impl IterMut for SingletonSet { - type IterMut<'a> = std::iter::Once<&'a mut T> + type IterMut<'a> + = std::iter::Once<&'a mut T> where Self: 'a; @@ -457,7 +476,8 @@ impl Len for EmptyMap { } } impl CollectionRef for EmptyMap { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -476,7 +496,8 @@ where } } impl CollectionMut for EmptyMap { - type ItemMut<'a> = &'a mut Self::Item + type ItemMut<'a> + = &'a mut Self::Item where Self: 'a; @@ -495,9 +516,10 @@ impl Keyed for EmptyMap { type Key = K; } impl KeyedRef for EmptyMap { - type KeyRef<'a> = &'a Self::Key - where - Self: 'a; + type KeyRef<'a> + = &'a Self::Key + where + Self: 'a; covariant_key_ref!(); } @@ -520,9 +542,10 @@ where } } impl Iter for EmptyMap { - type Iter<'a> = std::iter::Empty<&'a V> - where - Self: 'a; + type Iter<'a> + = std::iter::Empty<&'a V> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { std::iter::empty() @@ -532,18 +555,20 @@ impl SimpleKeyedRef for EmptyMap { simple_keyed_ref!(); } impl MapIter for EmptyMap { - type Iter<'a> = std::iter::Empty<(&'a K, &'a V)> - where - Self: 'a; + type Iter<'a> + = std::iter::Empty<(&'a K, &'a V)> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { std::iter::empty() } } impl MapIterMut for EmptyMap { - type IterMut<'a> = std::iter::Empty<(&'a K, &'a mut V)> - where - Self: 'a; + type IterMut<'a> + = std::iter::Empty<(&'a K, &'a mut V)> + where + Self: 'a; fn iter_mut(&mut self) -> Self::IterMut<'_> { std::iter::empty() @@ -576,7 +601,8 @@ impl Len for SingletonMap { } } impl CollectionRef for SingletonMap { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -595,7 +621,8 @@ where } } impl CollectionMut for SingletonMap { - type ItemMut<'a> = &'a mut Self::Item + type ItemMut<'a> + = &'a mut Self::Item where Self: 'a; @@ -614,9 +641,10 @@ impl Keyed for SingletonMap { type Key = K; } impl KeyedRef for SingletonMap { - type KeyRef<'a> = &'a Self::Key - where - Self: 'a; + type KeyRef<'a> + = &'a Self::Key + where + Self: 'a; covariant_key_ref!(); } @@ -639,9 +667,10 @@ where } } impl Iter for SingletonMap { - type Iter<'a> = std::iter::Once<&'a V> - where - Self: 'a; + type Iter<'a> + = std::iter::Once<&'a V> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { std::iter::once(&self.1) @@ -651,18 +680,20 @@ impl SimpleKeyedRef for SingletonMap { simple_keyed_ref!(); } impl MapIter for SingletonMap { - type Iter<'a> = std::iter::Once<(&'a K, &'a V)> - where - Self: 'a; + type Iter<'a> + = std::iter::Once<(&'a K, &'a V)> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { std::iter::once((&self.0, &self.1)) } } impl MapIterMut for SingletonMap { - type IterMut<'a> = std::iter::Once<(&'a K, &'a mut V)> - where - Self: 'a; + type IterMut<'a> + = std::iter::Once<(&'a K, &'a mut V)> + where + Self: 'a; fn iter_mut(&mut self) -> Self::IterMut<'_> { std::iter::once((&self.0, &mut self.1)) @@ -716,7 +747,8 @@ impl Len for OptionSet { } } impl CollectionRef for OptionSet { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -735,7 +767,8 @@ where } } impl CollectionMut for OptionSet { - type ItemMut<'a> = &'a mut T + type ItemMut<'a> + = &'a mut T where Self: 'a; @@ -751,16 +784,18 @@ where } } impl Iter for OptionSet { - type Iter<'a> = std::option::Iter<'a, T> - where - Self: 'a; + type Iter<'a> + = std::option::Iter<'a, T> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.0.iter() } } impl IterMut for OptionSet { - type IterMut<'a> = std::option::IterMut<'a, T> + type IterMut<'a> + = std::option::IterMut<'a, T> where Self: 'a; @@ -803,7 +838,8 @@ impl Len for OptionMap { } } impl CollectionRef for OptionMap { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -825,7 +861,8 @@ where } } impl CollectionMut for OptionMap { - type ItemMut<'a> = &'a mut Self::Item + type ItemMut<'a> + = &'a mut Self::Item where Self: 'a; @@ -847,9 +884,10 @@ impl Keyed for OptionMap { type Key = K; } impl KeyedRef for OptionMap { - type KeyRef<'a> = &'a Self::Key - where - Self: 'a; + type KeyRef<'a> + = &'a Self::Key + where + Self: 'a; covariant_key_ref!(); } @@ -878,9 +916,10 @@ where } } impl Iter for OptionMap { - type Iter<'a> = std::option::IntoIter<&'a V> - where - Self: 'a; + type Iter<'a> + = std::option::IntoIter<&'a V> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.0.as_ref().map(|(_k, v)| v).into_iter() @@ -890,18 +929,20 @@ impl SimpleKeyedRef for OptionMap { simple_keyed_ref!(); } impl MapIter for OptionMap { - type Iter<'a> = std::option::IntoIter<(&'a K, &'a V)> - where - Self: 'a; + type Iter<'a> + = std::option::IntoIter<(&'a K, &'a V)> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.0.as_ref().map(|(k, v)| (k, v)).into_iter() } } impl MapIterMut for OptionMap { - type IterMut<'a> = std::option::IntoIter<(&'a K, &'a mut V)> - where - Self: 'a; + type IterMut<'a> + = std::option::IntoIter<(&'a K, &'a mut V)> + where + Self: 'a; fn iter_mut(&mut self) -> Self::IterMut<'_> { self.0.as_mut().map(|(k, v)| (&*k, v)).into_iter() @@ -945,7 +986,8 @@ impl Len for ArraySet { } } impl CollectionRef for ArraySet { - type ItemRef<'a> = &'a T + type ItemRef<'a> + = &'a T where Self: 'a; @@ -967,7 +1009,8 @@ where } } impl CollectionMut for ArraySet { - type ItemMut<'a> = &'a mut T + type ItemMut<'a> + = &'a mut T where Self: 'a; @@ -986,9 +1029,10 @@ where } } impl Iter for ArraySet { - type Iter<'a> = std::slice::Iter<'a, T> - where - Self: 'a; + type Iter<'a> + = std::slice::Iter<'a, T> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.0.iter() @@ -1035,7 +1079,8 @@ impl Len for ArrayMap { } } impl CollectionRef for ArrayMap { - type ItemRef<'a> = &'a Self::Item + type ItemRef<'a> + = &'a Self::Item where Self: 'a; @@ -1057,7 +1102,8 @@ where } } impl CollectionMut for ArrayMap { - type ItemMut<'a> = &'a mut Self::Item + type ItemMut<'a> + = &'a mut Self::Item where Self: 'a; @@ -1079,9 +1125,10 @@ impl Keyed for ArrayMap { type Key = K; } impl KeyedRef for ArrayMap { - type KeyRef<'a> = &'a Self::Key - where - Self: 'a; + type KeyRef<'a> + = &'a Self::Key + where + Self: 'a; covariant_key_ref!(); } @@ -1110,9 +1157,10 @@ where } } impl Iter for ArrayMap { - type Iter<'a> = std::slice::Iter<'a, V> - where - Self: 'a; + type Iter<'a> + = std::slice::Iter<'a, V> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.vals.iter() @@ -1122,18 +1170,20 @@ impl SimpleKeyedRef for ArrayMap { simple_keyed_ref!(); } impl MapIter for ArrayMap { - type Iter<'a> = std::iter::Zip, std::slice::Iter<'a, V>> - where - Self: 'a; + type Iter<'a> + = std::iter::Zip, std::slice::Iter<'a, V>> + where + Self: 'a; fn iter(&self) -> Self::Iter<'_> { self.keys.iter().zip(self.vals.iter()) } } impl MapIterMut for ArrayMap { - type IterMut<'a> = std::iter::Zip, std::slice::IterMut<'a, V>> - where - Self: 'a; + type IterMut<'a> + = std::iter::Zip, std::slice::IterMut<'a, V>> + where + Self: 'a; fn iter_mut(&mut self) -> Self::IterMut<'_> { self.keys.iter().zip(self.vals.iter_mut()) diff --git a/lattices/src/ght/colt.rs b/lattices/src/ght/colt.rs new file mode 100644 index 000000000000..b4b22239cd81 --- /dev/null +++ b/lattices/src/ght/colt.rs @@ -0,0 +1,306 @@ +//! COLT from Wang/Willsey/Suciu + +use std::hash::Hash; + +use variadics::variadic_collections::VariadicCollection; +use variadics::{var_expr, var_type, PartialEqVariadic, SplitBySuffix, VariadicExt}; + +use crate::ght::{GeneralizedHashTrieNode, GhtGet, GhtInner, GhtLeaf}; + +/// Data structure design for our COLT is unique. +/// +/// In the paper, the COLT is an unbalanced trie that "grows upward" from leaves lazily +/// on access via the `force` method. +/// Unfortunately, unbalanced tries break our types: a node's type to be defined via the +/// type of its children, recursively -- meaning all paths need to be the same type (and length)! +/// +/// To work around this, our COLT is a variadic *list* GHTs (a forest) of increasing height, +/// starting with a trie of height 0 and continuing until a trie of height |key| - 1. +/// Our `force` method does not add a node above a leaf L as in the paper. Instead +/// it `take`s L from the current trie and merges it into the next trie to the right which is 1 taller. +// +/// The following trait provides the behavior we need from the nodes in a COLT forest. Every +/// `ColtForestNode` is a `GeneralizedHashTrieNode` with some extra methods. +pub trait ColtForestNode: GeneralizedHashTrieNode { + /// result of `force`ing a node + type Force: GeneralizedHashTrieNode; + + /// Force the generation of a parent node, as in the Wang/Willsey/Suciu COLT structure, + /// to be merged into the next trie to the right. + fn force(self) -> Option; + + /// Force the generation of a parent node but retain ref to this node + fn force_drain(&mut self) -> Option; +} + +// Force only acts on leaves +impl ColtForestNode for GhtInner +where + Head: 'static + Hash + Eq + Clone, + Node: 'static + ColtForestNode, + ::Schema: + SplitBySuffix::SuffixSchema)>, +{ + type Force = Node; // where Node:GeneralizedHashTrieNode; + fn force(self) -> Option { + None + } + + fn force_drain(&mut self) -> Option { + None + } +} + +// Leaf case +impl ColtForestNode + for GhtLeaf +where + Head: 'static + Clone + Hash + Eq, + Rest: 'static + Clone + Hash + Eq + VariadicExt, + Schema: 'static + Hash + Eq + Clone + VariadicExt + PartialEqVariadic, + Rest: PartialEqVariadic, + Schema: SplitBySuffix, + Schema: SplitBySuffix, + >::Prefix: Eq + Hash + Clone, + >::Prefix: Eq + Hash + Clone, + Storage: VariadicCollection + Default + IntoIterator, + GhtLeaf: GeneralizedHashTrieNode, + GhtInner>: + GeneralizedHashTrieNode, +{ + type Force = GhtInner>; + fn force(mut self) -> Option { + let mut retval = Self::Force::default(); + self.forced = true; + for row in self.into_iter().unwrap() { + retval.insert(row); + } + Some(retval) + } + + fn force_drain(&mut self) -> Option>> { + let mut retval = Self::Force::default(); + self.forced = true; + for row in self.elements.drain() { + retval.insert(row); + } + Some(retval) + } +} + +/// Emulate the `get` and iter` functions for a single Ght node +/// [`GhtGet`] across a forest of ColtForestNodes. +/// +/// The "current" ColtGet node (corresponding to the "current" GhtGet node) at depth +/// d from the root is a variadic list of nodes, each at depth d in its their +/// respective trie in the forest, Tries of height d or smaller are omitted, +/// hence the first element in any ColtGet is a GhtLeaf. +pub trait ColtGet { + /// Schema variadic: the schema of the relation stored in this COLT. + /// This type is the same in all Tries and nodes of the COLT. + type Schema: VariadicExt + Eq + Hash + Clone; + /// The type of Storage + /// This type is the same in all Tries and nodes of the COLT + type Storage: VariadicCollection; + /// SuffixSchema variadic: the suffix of the schema *from this node of the trie + /// downward*. The first entry in this variadic is of type Head. + /// This type is the same in all Tries of the COLT (but changes as we traverse downward) + type SuffixSchema: VariadicExt + Eq + Hash + Clone; + /// The type of the first column in the SuffixSchema + /// This type is the same in all Tries of the COLT (but changes as we traverse downward) + type Head: Eq + Hash; + + /// Type returned by [`Self::get`]. + type Get; + + /// Following the spec in Wang/Willsey/Suciu, on an Inner node this retrieves the value + /// (child) associated with the given "head" key. It returns an `Option` containing a + /// reference to the value if found, or `None` if not found. + /// On a Leaf node, returns None. + fn get(self, head: &Self::Head) -> Self::Get; + + /// Iterator for the "head" keys (from inner nodes) or nothing (from leaf nodes). + fn iter(&self) -> impl Iterator; +} + +/// `ColtGet` without the first (head) trie. +pub trait ColtGetTail: ColtGet { + /// merge an inner node into the head of this tail of the forest + fn merge(&mut self, inner_to_merge: InnerToMerge); +} + +impl<'a, Rest, Schema, SuffixSchema, Storage> ColtGet for var_type!(&'a mut GhtLeaf, ...Rest) +where + Rest: ColtGetTail< + as ColtForestNode>::Force, + Storage = Storage, + >, + ::SuffixSchema: 'a, + GhtLeaf: ColtForestNode, + Schema: Clone + Hash + Eq + VariadicExt, + SuffixSchema: Clone + Hash + Eq + VariadicExt, + Storage: VariadicCollection, +{ + type Schema = Schema; + type Head = Rest::Head; + type SuffixSchema = SuffixSchema; + type Get = Rest::Get; + type Storage = Rest::Storage; + + fn get(self, head: &Self::Head) -> Self::Get { + let (first, mut rest) = self; + let forced = first.force_drain().unwrap(); + ColtGetTail::merge(&mut rest, forced); + Rest::get(rest, head) + } + + fn iter(&self) -> impl Iterator { + std::iter::empty() + } +} + +// we only merge in GhtInner> nodes, so this +// should never be called. +impl<'a, Rest, Schema, SuffixSchema, T, Storage> ColtGetTail for var_type!(&'a mut GhtLeaf, ...Rest) +where + Rest: ColtGetTail< + as ColtForestNode>::Force, + Storage = Storage, + >, + ::SuffixSchema: 'a, + GhtLeaf: ColtForestNode, + Schema: Clone + Hash + Eq + VariadicExt, + SuffixSchema: Clone + Hash + Eq + VariadicExt, + Storage: VariadicCollection, +{ + fn merge(&mut self, _inner_to_merge: T) { + panic!(); + } +} + +impl<'a, Head, Head2, Rest, Node> ColtGet for var_type!(&'a mut GhtInner>, ...Rest) +where + Rest: ColtGet, + Head: Eq + Hash + Clone, + Head2: Eq + Hash + Clone, + Node: GeneralizedHashTrieNode, + GhtInner>: GeneralizedHashTrieNode< + Head = Rest::Head, + SuffixSchema = Rest::SuffixSchema, + Schema = Rest::Schema, + Storage = Rest::Storage, + >, + GhtInner: GeneralizedHashTrieNode, +{ + type Schema = Rest::Schema; + type Head = Rest::Head; + type SuffixSchema = Rest::SuffixSchema; + type Get = var_type!(&'a mut GhtInner, ...Rest::Get); + type Storage = Rest::Storage; + + fn get(self, head: &Self::Head) -> Self::Get { + let (first, rest) = self; + // create a child entry here for this get, to absorb future forces + // TODO(mingwei): extra clone here if entry already exists. + let child = first.children.entry(head.clone()).or_default(); + var_expr!(child, ...Rest::get(rest, head)) + } + + fn iter(&self) -> impl Iterator { + self.0.children.keys().cloned().chain(Rest::iter(&self.1)) + } +} + +impl<'a, Head, Rest, Schema, ValType, Storage> ColtGet for var_type!(&'a mut GhtInner>, ...Rest) +where + Rest: ColtGet, + Head: Eq + Hash + Clone, + Schema: Eq + Hash + Clone + PartialEqVariadic, + ValType: Eq + Hash + Clone + PartialEqVariadic, + Storage: VariadicCollection, + GhtLeaf: GeneralizedHashTrieNode, + Schema: 'static + Eq + VariadicExt + Hash + Clone + SplitBySuffix + PartialEqVariadic, + >::Prefix: Eq + Hash + Clone, + GhtInner>: + GeneralizedHashTrieNode + GhtGet, + GhtInner>: + GeneralizedHashTrieNode, + GhtLeaf: + GeneralizedHashTrieNode + GhtGet, +{ + type Schema = Rest::Schema; + type Head = Rest::Head; + type SuffixSchema = Rest::SuffixSchema; + type Get = var_type!(&'a mut GhtLeaf, ...Rest::Get); + type Storage = Rest::Storage; + + fn get(self, head: &Self::Head) -> Self::Get { + let (first, rest) = self; + let child = first.children.entry(head.clone()).or_default(); + var_expr!(child, ...Rest::get(rest, head)) + } + + fn iter(&self) -> impl Iterator { + self.0.children.keys().cloned().chain(Rest::iter(&self.1)) + } +} + +impl<'a, Head, Rest, Schema, ValType, Storage> + ColtGetTail>> for var_type!(&'a mut GhtInner>, ...Rest) +where + Rest: ColtGet, + Head: Eq + Hash + Clone, + Schema: Eq + Hash + Clone + PartialEqVariadic, + ValType: Eq + Hash + Clone + PartialEqVariadic, + Storage: VariadicCollection, + var_type!(&'a mut GhtInner>, ...Rest): + ColtGet, + GhtLeaf: GeneralizedHashTrieNode, + Schema: 'static + Eq + VariadicExt + Hash + Clone + SplitBySuffix + PartialEqVariadic, + >::Prefix: Eq + Hash + Clone, + GhtInner>: + GeneralizedHashTrieNode + GhtGet, +{ + fn merge(&mut self, inner_to_merge: GhtInner>) { + let (head, _rest) = self; + // can't use Merge with COLT bc columnstore is not a lattice!! + head.merge_node(inner_to_merge); + } +} + +impl<'a, Head, Node> ColtGet for var_type!(&'a mut GhtInner) +where + GhtInner: GeneralizedHashTrieNode, + Head: Clone + Eq + Hash, + Node: GeneralizedHashTrieNode, +{ + type Schema = as GeneralizedHashTrieNode>::Schema; + type SuffixSchema = as GeneralizedHashTrieNode>::SuffixSchema; + type Head = Head; + type Get = var_type!(&'a mut Node); + type Storage = Node::Storage; + + fn get(self, head: &Self::Head) -> Self::Get { + let child = self.0.children.entry(head.clone()).or_default(); + var_expr!(child) + } + + fn iter(&self) -> impl Iterator { + self.0.children.keys().cloned() + } +} +impl ColtGetTail>> for var_type!(&mut GhtInner>) +where + GhtInner>: + GeneralizedHashTrieNode + GhtGet, + GhtLeaf: GeneralizedHashTrieNode, + Head: Clone + Eq + Hash, + Schema: Clone + Eq + Hash + VariadicExt, + Storage: VariadicCollection, +{ + fn merge(&mut self, inner_to_merge: GhtInner>) { + let (head, _rest) = self; + // can't use Merge with COLT bc columnstore is not a lattice!! + head.merge_node(inner_to_merge); + } +} diff --git a/lattices/src/ght/lattice.rs b/lattices/src/ght/lattice.rs new file mode 100644 index 000000000000..11b8a6aabdec --- /dev/null +++ b/lattices/src/ght/lattice.rs @@ -0,0 +1,439 @@ +//! Lattice traits for GHT + +use core::cmp::Ordering::{Equal, Greater, Less}; +use std::cmp::Ordering; +use std::collections::HashMap; +use std::hash::Hash; + +use variadics::variadic_collections::VariadicSet; +use variadics::{var_expr, var_type, CloneVariadic, PartialEqVariadic, SplitBySuffix, VariadicExt}; + +use crate::ght::{GeneralizedHashTrieNode, GhtGet, GhtInner, GhtLeaf}; +use crate::{IsBot, IsTop, LatticeBimorphism, LatticeOrd, Merge}; + +impl Merge> for GhtInner +where + Node: GeneralizedHashTrieNode + Merge, + Node::Storage: VariadicSet, // multiset is not a lattice! + Self: GeneralizedHashTrieNode, + Head: Hash + Eq + Clone, +{ + fn merge(&mut self, other: GhtInner) -> bool { + let mut changed = false; + + for (k, v) in other.children { + match self.children.entry(k) { + std::collections::hash_map::Entry::Occupied(mut occupied) => { + changed |= occupied.get_mut().merge_node(v); + } + std::collections::hash_map::Entry::Vacant(vacant) => { + vacant.insert(v); + changed = true; + } + } + } + changed + } +} + +impl Merge> + for GhtLeaf +where + Schema: Eq + Hash, + Storage: VariadicSet + Extend + IntoIterator, +{ + fn merge(&mut self, other: GhtLeaf) -> bool { + let old_len = self.elements.len(); + self.elements.extend(other.elements); + self.elements.len() > old_len + } +} + +impl PartialEq> for GhtInner +where + Head: Hash + Eq + 'static + Clone, + Node: GeneralizedHashTrieNode + 'static + PartialEq, + Node::Storage: VariadicSet, // multiset is not a lattice! + Node::Schema: SplitBySuffix, + GhtInner: GhtGet, + as GhtGet>::Get: PartialEq, +{ + fn eq(&self, other: &GhtInner) -> bool { + if self.children.len() != other.children.len() { + return false; + } + + for head in self.iter() { + let other_node = other.get(&head); + if other_node.is_none() { + return false; + } + let this_node = self.get(&head); + if this_node.is_none() { + return false; + } + if this_node.unwrap() != other_node.unwrap() { + return false; + } + } + true + } +} + +impl PartialOrd> for GhtInner +where + Head: Hash + Eq + 'static + Clone, + Node: 'static + GeneralizedHashTrieNode + PartialEq + PartialOrd, + Node::Storage: VariadicSet, // multiset is not a lattice! + Node::Schema: SplitBySuffix, +{ + fn partial_cmp(&self, other: &GhtInner) -> Option { + let mut self_any_greater = false; + let mut other_any_greater = false; + if self.children.is_empty() && other.children.is_empty() { + Some(Equal) + } else { + for k in self.children.keys().chain(other.children.keys()) { + match (self.children.get(k), other.children.get(k)) { + (Some(self_value), Some(other_value)) => { + match self_value.partial_cmp(other_value)? { + Greater => { + self_any_greater = true; + } + Less => { + other_any_greater = true; + } + Equal => {} + } + } + (Some(_), None) => { + self_any_greater = true; + } + (None, Some(_)) => { + other_any_greater = true; + } + (None, None) => unreachable!(), + } + } + match (self_any_greater, other_any_greater) { + (true, false) => Some(Greater), + (false, true) => Some(Less), + (false, false) => Some(Equal), + (true, true) => unreachable!(), + } + } + } +} + +impl PartialOrd> + for GhtLeaf +where + Schema: Eq + Hash + PartialEqVariadic, + SuffixSchema: Eq + Hash, + Storage: VariadicSet + PartialEq, +{ + fn partial_cmp(&self, other: &GhtLeaf) -> Option { + match self.elements.len().cmp(&other.elements.len()) { + Greater => { + if other.elements.iter().all(|tup| self.elements.contains(tup)) { + Some(Greater) + } else { + None + } + } + Equal => { + if self + .elements + .iter() + .all(|head| other.elements.contains(head)) + { + Some(Equal) + } else { + None + } + } + Less => { + if self + .elements + .iter() + .all(|head| other.elements.contains(head)) + { + Some(Less) + } else { + None + } + } + } + } +} + +impl LatticeOrd> for GhtInner +where + Self: PartialOrd>, + Head: Clone, + Node: GeneralizedHashTrieNode, + Node::Storage: VariadicSet, // multiset is not a lattice! +{ +} +impl LatticeOrd> + for GhtLeaf +where + Schema: Eq + Hash + PartialEqVariadic, + SuffixSchema: Eq + Hash, + Storage: VariadicSet + PartialEq, +{ +} + +impl IsBot for GhtInner +where + Head: Clone, + Node: GeneralizedHashTrieNode + IsBot, +{ + fn is_bot(&self) -> bool { + self.children.iter().all(|(_, v)| v.is_bot()) + } +} + +impl IsBot for GhtLeaf +where + Schema: Eq + Hash, + SuffixSchema: Eq + Hash, + Storage: VariadicSet, +{ + fn is_bot(&self) -> bool { + self.elements.is_empty() + } +} + +impl IsTop for GhtInner +where + Head: Clone, + Node: GeneralizedHashTrieNode, + Node::Storage: VariadicSet, // multiset is not a lattice! +{ + fn is_top(&self) -> bool { + false + } +} + +impl IsTop for GhtLeaf +where + Schema: Eq + Hash, + SuffixSchema: Eq + Hash, + Storage: VariadicSet, +{ + fn is_top(&self) -> bool { + false + } +} + +////////////////////////// +// BiMorphisms for GHT +// + +/// Bimorphism for the cartesian product of two GHT *subtries*. +/// +/// Output is a set of all possible pairs of +/// *suffixes* from the two subtries. If you use this at the root of a GHT, it's a full cross-product. +/// If you use this at an internal node, it provides a 'factorized' representation with only the suffix +/// cross-products expanded. +pub struct GhtCartesianProductBimorphism { + _phantom: std::marker::PhantomData GhtOut>, +} +impl Default for GhtCartesianProductBimorphism { + fn default() -> Self { + Self { + _phantom: Default::default(), + } + } +} +impl<'a, 'b, GhtA, GhtB, GhtOut> LatticeBimorphism<&'a GhtA, &'b GhtB> + for GhtCartesianProductBimorphism +where + GhtA: GeneralizedHashTrieNode, + GhtA::Storage: VariadicSet, // multiset is not a lattice! + GhtB: GeneralizedHashTrieNode, + GhtB::Storage: VariadicSet, // multiset is not a lattice! + GhtOut: FromIterator, + GhtA::SuffixSchema: CloneVariadic, + GhtB::SuffixSchema: CloneVariadic, +{ + type Output = GhtOut; + + fn call(&mut self, ght_a: &'a GhtA, ght_b: &'b GhtB) -> Self::Output { + ght_a.recursive_iter().flat_map(|a| { + let (_a_prefix, a_suffix) = >::split_by_suffix_ref(a); + ght_b + .recursive_iter() + .map(move |b| { + let (_b_prefix, b_suffix) = >::split_by_suffix_ref(b); + var_expr!(...::clone_ref_var(a_suffix), ...::clone_ref_var(b_suffix)) + }) + }).collect() + } +} + +/// Forms the cartesian product of the ValTypes only +/// Used on GhtLeaf nodes to implement DeepJoinLatticeBimorphism +pub struct GhtValTypeProductBimorphism { + _phantom: std::marker::PhantomData GhtOut>, +} +impl Default for GhtValTypeProductBimorphism { + fn default() -> Self { + Self { + _phantom: Default::default(), + } + } +} +impl<'a, 'b, GhtA, GhtB, GhtOut> LatticeBimorphism<&'a GhtA, &'b GhtB> + for GhtValTypeProductBimorphism +where + GhtA: GeneralizedHashTrieNode, + GhtA::Storage: VariadicSet, // multiset is not a lattice! + GhtB: GeneralizedHashTrieNode, + GhtB::Storage: VariadicSet, // multiset is not a lattice! + GhtOut: FromIterator, + GhtA::Schema: Eq + Hash + CloneVariadic, + GhtB::Schema: Eq + Hash + SplitBySuffix, + GhtB::ValType: CloneVariadic, +{ + type Output = GhtOut; + + fn call(&mut self, ght_a: &'a GhtA, ght_b: &'b GhtB) -> Self::Output { + ght_a.recursive_iter().flat_map(|a| { + ght_b + .recursive_iter() + .map(move |b| { + let (_prefix_b, suffix_b) + = >::split_by_suffix_ref(b); + var_expr!(...::clone_ref_var(a), ...::clone_ref_var(suffix_b)) + } + ) + }).collect() + } +} + +/// Composable bimorphism, wraps an existing morphism by partitioning it per key. +/// +/// For example, `GhtKeyedBimorphism<..., GhtCartesianProduct<...>>` is a join. +#[derive(Default)] +pub struct GhtBimorphism { + bimorphism: Bimorphism, + // _phantom: std::marker::PhantomData MapOut>, +} +impl GhtBimorphism { + /// Create a `KeyedBimorphism` using `bimorphism` for handling values. + pub fn new(bimorphism: Bimorphism) -> Self { + Self { + bimorphism, + // _phantom: std::marker::PhantomData, + } + } +} + +impl LatticeBimorphism for GhtBimorphism +where + GhtA: GeneralizedHashTrieNode, + GhtA::Storage: VariadicSet, // multiset is not a lattice! + GhtB: GeneralizedHashTrieNode, + GhtB::Storage: VariadicSet, // multiset is not a lattice! + GhtOut: GeneralizedHashTrieNode, // FromIterator, + for<'a, 'b> ValFunc: LatticeBimorphism<&'a GhtA, &'b GhtB, Output = GhtOut>, +{ + type Output = GhtOut; + + fn call(&mut self, ght_a: GhtA, ght_b: GhtB) -> Self::Output { + let node_bim = &mut self.bimorphism; // GhtNodeKeyedBimorphism::::new(self.bimorphism); + node_bim.call(&ght_a, &ght_b) + } +} + +#[derive(Default)] +/// bimorphism trait for equijoining Ght Nodes +pub struct GhtNodeKeyedBimorphism { + bimorphism: Bimorphism, +} +/// bimorphism implementation for equijoining Ght Nodes +impl GhtNodeKeyedBimorphism { + /// initialize bimorphism + pub fn new(bimorphism: Bimorphism) -> Self { + Self { bimorphism } + } +} +/// bimorphism implementation for equijoining Ght Nodes +impl<'a, 'b, Head, GhtA, GhtB, ValFunc> LatticeBimorphism<&'a GhtA, &'b GhtB> + for GhtNodeKeyedBimorphism +where + Head: Clone + Hash + Eq, + ValFunc: LatticeBimorphism<&'a GhtA::Get, &'b GhtB::Get>, + ValFunc::Output: GeneralizedHashTrieNode, + GhtA: GeneralizedHashTrieNode + GhtGet, + GhtB: GeneralizedHashTrieNode + GhtGet, + GhtA::Storage: VariadicSet, // multiset is not a lattice! + GhtB::Storage: VariadicSet, // multiset is not a lattice! + ::AsRefVar<'a>: CloneVariadic, + ::AsRefVar<'b>: CloneVariadic, +{ + type Output = GhtInner; // HashMap; // GhtOut; + + fn call(&mut self, ght_a: &'a GhtA, ght_b: &'b GhtB) -> Self::Output { + let mut children = HashMap::::new(); + // for head in ght_b.iter_keys() { + for head in ght_b.iter() { + if let Some(get_a) = ght_a.get(&head) { + let get_b = ght_b.get(&head).unwrap(); + let val = self.bimorphism.call(get_a, get_b); + children.insert(head.clone(), val); + } + } + GhtInner { children } + } +} + +/// bimorphism trait for equijoin on full tuple (keys in all GhtInner nodes) +pub trait DeepJoinLatticeBimorphism { + /// bimorphism type for equijoin on full tuple (keys in all GhtInner nodes) + type DeepJoinLatticeBimorphism; +} +/// bimorphism implementation for equijoin on full tuple (keys in all GhtInner nodes) +impl DeepJoinLatticeBimorphism + for (GhtInner, GhtInner) +where + Head: 'static + Hash + Eq + Clone, + NodeA: 'static + GeneralizedHashTrieNode, + NodeB: 'static + GeneralizedHashTrieNode, + NodeA::Storage: VariadicSet, // multiset is not a lattice! + NodeB::Storage: VariadicSet, // multiset is not a lattice! + (NodeA, NodeB): DeepJoinLatticeBimorphism, + Storage: VariadicSet, +{ + type DeepJoinLatticeBimorphism = GhtNodeKeyedBimorphism< + <(NodeA, NodeB) as DeepJoinLatticeBimorphism>::DeepJoinLatticeBimorphism, + >; +} +impl + DeepJoinLatticeBimorphism + for ( + GhtLeaf, + GhtLeaf, + ) +where + SchemaA: 'static + VariadicExt + Eq + Hash + SplitBySuffix, /* + AsRefVariadicPartialEq */ + ValTypeA: 'static + VariadicExt + Eq + Hash, // + AsRefVariadicPartialEq + SchemaB: 'static + VariadicExt + Eq + Hash + SplitBySuffix, /* + AsRefVariadicPartialEq */ + ValTypeB: 'static + VariadicExt + Eq + Hash, // + AsRefVariadicPartialEq + StorageA: VariadicSet, + StorageB: VariadicSet, + StorageOut: VariadicSet, + for<'x> SchemaA::AsRefVar<'x>: CloneVariadic, + for<'x> SchemaB::AsRefVar<'x>: CloneVariadic, + var_type!(...SchemaA, ...ValTypeB): Eq + Hash, +{ + type DeepJoinLatticeBimorphism = GhtValTypeProductBimorphism< + GhtLeaf< + var_type!(...SchemaA, ...ValTypeB), + var_type!(...ValTypeA, ...ValTypeB), + StorageOut, + >, + >; +} diff --git a/lattices/src/ght/macros.rs b/lattices/src/ght/macros.rs new file mode 100644 index 000000000000..174f124518ef --- /dev/null +++ b/lattices/src/ght/macros.rs @@ -0,0 +1,117 @@ +//! Macros for GHT +#[macro_export] +/// Internal macro for constructing a Ght struct with the given schema and storage type +/// +/// Should not be used directly, use `GhtType!` instead +macro_rules! GhtTypeWithSchema { + // Empty key & Val (Leaf) + (() => () => $( $schema:ty ),+ : $storage:ident) => ( + $crate::ght::GhtLeaf::<$( $schema ),*, () > + ); + + // Empty key (Leaf) + (() => $( $z:ty ),* => $schema:ty : $storage:ident) => ( + $crate::ght::GhtLeaf::<$schema, $crate::variadics::var_type!($( $z ),*), $crate::variadics::variadic_collections::$storage<$schema> > + ); + + // Singleton key & Empty val (Inner over Leaf) + ($a:ty => () => $schema:ty : $storage:ident) => ( + $crate::ght::GhtInner::<$a, $crate::ght::GhtLeaf::<$schema, (), $crate::variadics::variadic_collections::$storage<$schema> >> + ); + + // Singleton key (Inner over Leaf) + ($a:ty => $( $z:ty ),* => $schema:ty : $storage:ident) => ( + $crate::ght::GhtInner::<$a, $crate::ght::GhtLeaf::<$schema, $crate::variadics::var_type!($( $z ),*), $crate::variadics::variadic_collections::$storage<$schema> >> + ); + + // Recursive case with empty val + ($a:ty, $( $b:ty ),* => () => $schema:ty : $storage:ident) => ( + $crate::ght::GhtInner::<$a, $crate::GhtTypeWithSchema!($( $b ),* => () => $schema : $storage)> + ); + + // Recursive case + ($a:ty, $( $b:ty ),* => $( $z:ty ),* => $schema:ty : $storage:ident) => ( + $crate::ght::GhtInner::<$a, $crate::GhtTypeWithSchema!($( $b ),* => $( $z ),* => $schema : $storage)> + ); +} + +#[macro_export] +/// Public macro for constructing a Ght struct with the given schema and storage type +/// +/// # Example +/// ``` +/// use lattices::GhtType; +/// use variadics::variadic_collections::VariadicHashSet; +/// +/// // This generates a Ght struct with (u16, u32) as key, (u64) as val, and VariadicHashSet as storage +/// type MyHashGht = GhtType!(u16, u32 => u64: VariadicHashSet); +/// let my_ght = MyHashGht::default(); +/// +/// /// // This generates a Ght struct with (u16, u32) as key, () as val, and VariadicCountedHashSet as storage +/// type MyMultisetGht = GhtType!(u16, u32 => (): VariadicCountedHashSet); +/// let my_ght = MyMultisetGht::default(); +/// +/// // This generates a Ght struct with (u16, u32) as key, () as val, and VariadicColumnSet as storage +/// type MyColumnarMultisetGht = GhtType!(u16, u32 => (): VariadicColumnMultiset); +/// let my_ght = MyColumnarMultisetGht::default(); +/// ``` +macro_rules! GhtType { + // Empty key + (() => $( $z:ty ),*: $storage:ident) => ( + $crate::GhtTypeWithSchema!(() => $( $z ),* => $crate::variadics::var_type!($( $z ),*): $storage) + ); + + // Recursive case empty val + ($( $b:ty ),* => (): $storage:ident) => ( + $crate::GhtTypeWithSchema!($( $b ),* => () => $crate::variadics::var_type!($( $b ),*): $storage) + ); + + // Recursive case + ($( $b:ty ),* => $( $z:ty ),*: $storage:ident) => ( + $crate::GhtTypeWithSchema!($( $b ),* => $( $z ),* => $crate::variadics::var_type!($( $b ),*, $( $z ),*): $storage) + ); +} + +#[macro_export] +/// Construct a forest of Ghts (i.e. a ColtForest) with the given schema and storage type. +/// +/// # Example +/// ``` +/// use lattices::ColtType; +/// +/// type MyColt = ColtType!(u16, u32, u64); +/// ``` +macro_rules! ColtType { + // Base case: single type to empty + ($a:ty => ()) => { + $crate::variadics::var_type!($crate::GhtType!($a => (): VariadicColumnMultiset)) + }; + // Base case: single type to single type + ($a:ty => $c:ty) => { + ($crate::GhtType!($a => $c: VariadicColumnMultiset), $crate::ColtType!($a, $c => ())) + }; + // Recursive case: single type to multiple types + ($a:ty => $c:ty, $( $d:ty ),*) => { + ($crate::GhtType!($a => $c, $( $d ),*: VariadicColumnMultiset), $crate::ColtType!($a, $c => $( $d ),*)) + }; + // Base case: multiple types to empty + ($a:ty, $( $b:ty ),* => ()) => { + $crate::variadics::var_type!($crate::GhtType!($a, $( $b ),* => (): VariadicColumnMultiset)) + }; + // Base case: multiple types to single type + ($a:ty, $( $b:ty ),* => $c:ty) => { + ($crate::GhtType!($a, $( $b ),* => $c: VariadicColumnMultiset), $crate::ColtType!($a, $( $b ),*, $c => ())) + }; + // Recursive case: multiple types to multiple types + ($a:ty, $( $b:ty ),* => $c:ty, $( $d:ty ),*) => { + ($crate::GhtType!($a, $( $b ),* => $c, $( $d ),*: VariadicColumnMultiset), $crate::ColtType!($a, $( $b ),*, $c => $( $d ),*)) + }; + // General case: single type + ($a:ty) => { + ($crate::GhtType!(() => $a: VariadicColumnMultiset), $crate::ColtType!($a => ())) + }; + // General case: multiple types + ($a:ty, $( $b:ty ),*) => { + ($crate::GhtType!(() => $a, $( $b ),*: VariadicColumnMultiset), $crate::ColtType!($a => $( $b ),*)) + }; +} diff --git a/lattices/src/ght/mod.rs b/lattices/src/ght/mod.rs new file mode 100644 index 000000000000..9496a43cd1e6 --- /dev/null +++ b/lattices/src/ght/mod.rs @@ -0,0 +1,545 @@ +//! GHT from the Wang/Willsey/Suciu Freejoin work +use std::collections::HashMap; +use std::fmt::Debug; +use std::hash::Hash; +use std::marker::PhantomData; + +use variadics::variadic_collections::VariadicCollection; +use variadics::{ + var_args, var_type, PartialEqVariadic, RefVariadic, Split, SplitBySuffix, VariadicExt, +}; + +pub mod colt; +pub mod lattice; +pub mod macros; +pub mod test; + +/// The GeneralizedHashTrieNode trait captures the properties of nodes in a Ght. +/// +/// The Ght, defined by Wang/Willsey/Suciu, is a hash-based trie for storing tuples. +/// It is parameterized by an ordered schema [`VariadicExt`] of the relation stored in the trie. +/// It is a tree of [`GhtInner`] nodes, with [`GhtLeaf`] nodes at the leaves. +/// The trie is keyed on a prefix of the schema [`Self::KeyType`], +/// and the remaining columns [`Self::ValType`] are stored in the leaf. +/// All leaf nodes use the same `[Self::Storage]` type to store the data. +pub trait GeneralizedHashTrieNode: Default { + // types that are the same in all nodes of the trie + /// Schema variadic: the schema of the relation stored in this trie. + type Schema: VariadicExt + Eq + Hash + Clone + SplitBySuffix; + /// The prefix of columns in [`Self::Schema`] that the trie is keyed on + type KeyType: VariadicExt + Eq + Hash + Clone; + /// The suffix of columns in [`Self::Schema`] that are not part of the trie keys + type ValType: VariadicExt + Eq + Hash + Clone; + /// The type that holds the data in the leaves + type Storage: VariadicCollection + + Default + + IntoIterator; + + // types that vary per node + /// SuffixSchema variadic: the suffix of [`Self::Schema`] from this node of the trie + /// downward. The first entry in this variadic is of type [`Self::Head`]. + type SuffixSchema: VariadicExt + Eq + Hash + Clone; + /// The first field in [`Self::SuffixSchema`], and the key for the next node in the trie. + type Head: Eq + Hash + Clone; + + /// Create a new Ght from the iterator. + fn new_from(input: impl IntoIterator) -> Self; + + /// Merge a matching Ght node into this node + fn merge_node(&mut self, other: Self) -> bool; + + /// Report the height of this node. This is the length of path from this node to a leaf - 1. + /// E.g. if we have GhtInner> the height is 2 + /// This is a static property of the type of this node, so simply invokes the static method. + fn height(&self) -> usize { + Self::HEIGHT + } + + /// The height of this node in the GhT. Leaf = 0. + const HEIGHT: usize; + + /// Inserts an item into the hash trie. + fn insert(&mut self, row: Self::Schema) -> bool; + + /// Returns `true` if the (entire) row is found below in the trie, `false` otherwise. + /// See [`GhtGet::get`] to look just for "head" keys in this node + fn contains<'a>(&'a self, row: ::AsRefVar<'a>) -> bool; + + /// Iterate through (entire) rows stored in this HashTrie. + fn recursive_iter(&self) -> impl Iterator::AsRefVar<'_>>; + + /// return the leaf below that contains this row, or `None` if not found. + fn find_containing_leaf( + &self, + row: ::AsRefVar<'_>, + ) -> Option<&'_ GhtLeaf>; + + /// into_iter for leaf elements, or None for inner nodes + fn into_iter(self) -> Option>; + + /// pull all the data out of this trie node but retain the reference + fn drain(&mut self) -> Option>; +} + +/// internal node of a HashTrie +#[derive(Debug, Clone)] +pub struct GhtInner +where + Head: Clone, + Node: GeneralizedHashTrieNode, +{ + pub(crate) children: HashMap, +} + +impl Default for GhtInner +where + Head: Clone, + Node: GeneralizedHashTrieNode, +{ + fn default() -> Self { + let children = Default::default(); + Self { children } + } +} + +impl GeneralizedHashTrieNode for GhtInner +where + Head: 'static + Hash + Eq + Clone, + Node: 'static + GeneralizedHashTrieNode, + Node::Schema: SplitBySuffix, +{ + type Schema = Node::Schema; + type KeyType = Node::KeyType; + type ValType = Node::ValType; + type Storage = Node::Storage; + type SuffixSchema = var_type!(Head, ...Node::SuffixSchema); + type Head = Head; + + fn new_from(input: impl IntoIterator) -> Self { + let mut retval: Self = Default::default(); + for row in input { + retval.insert(row); + } + retval + } + + fn merge_node(&mut self, other: Self) -> bool { + let mut changed = false; + + for (k, v) in other.children { + match self.children.entry(k) { + std::collections::hash_map::Entry::Occupied(mut occupied) => { + changed |= occupied.get_mut().merge_node(v) + } + std::collections::hash_map::Entry::Vacant(vacant) => { + vacant.insert(v); + changed = true + } + } + } + changed + } + + const HEIGHT: usize = Node::HEIGHT + 1; + + fn insert(&mut self, row: Self::Schema) -> bool { + let (_prefix, var_args!(head, ..._rest)) = + Self::Schema::split_by_suffix_ref(row.as_ref_var()); + self.children.entry(head.clone()).or_default().insert(row) + } + + fn contains<'a>(&'a self, row: ::AsRefVar<'a>) -> bool { + let (_prefix, var_args!(head, ..._rest)) = Self::Schema::split_by_suffix_ref(row); + if let Some(node) = self.children.get(head) { + node.contains(row) + } else { + false + } + } + + fn recursive_iter(&self) -> impl Iterator::AsRefVar<'_>> { + self.children + .iter() + .flat_map(|(_k, vs)| vs.recursive_iter()) + } + + fn find_containing_leaf( + &self, + row: ::AsRefVar<'_>, + ) -> Option<&'_ GhtLeaf> { + let (_prefix, var_args!(head, ..._rest)) = Self::Schema::split_by_suffix_ref(row); + self.children + .get(head) + .and_then(|child| child.find_containing_leaf(row)) + } + + fn into_iter(self) -> Option> { + None::>> + } + + fn drain(&mut self) -> Option> { + None::>> + } +} + +impl FromIterator for GhtInner +where + Head: 'static + Hash + Eq + Clone, + Node: 'static + GeneralizedHashTrieNode + Clone, + Node::Schema: SplitBySuffix, +{ + fn from_iter>(iter: Iter) -> Self { + let mut out = Self::default(); + for row in iter { + out.insert(row); + } + out + } +} + +/// leaf node of a HashTrie +#[derive(Debug, PartialEq, Eq, Clone)] +pub struct GhtLeaf +where + Schema: Eq + Hash, + Storage: VariadicCollection, +{ + pub(crate) elements: Storage, + pub(crate) forced: bool, + /// defines ValType for the parents, recursively + pub(crate) _suffix_schema: PhantomData, +} +impl Default for GhtLeaf +where + Schema: Eq + Hash, + Storage: VariadicCollection + Default, +{ + fn default() -> Self { + let elements = Storage::default(); + Self { + elements, + forced: false, + _suffix_schema: PhantomData, + } + } +} + +impl GeneralizedHashTrieNode + for GhtLeaf +where + Schema: 'static + + Eq + + VariadicExt + + Hash + + Clone + + SplitBySuffix + + PartialEqVariadic, + ValHead: Clone + Eq + Hash, + var_type!(ValHead, ...ValRest): Clone + Eq + Hash + PartialEqVariadic, + >::Prefix: Eq + Hash + Clone, + Storage: VariadicCollection + Default + IntoIterator, +{ + type Schema = Schema; + type SuffixSchema = var_type!(ValHead, ...ValRest); + type ValType = var_type!(ValHead, ...ValRest); + type KeyType = >::Prefix; + type Head = ValHead; + type Storage = Storage; + + fn new_from(input: impl IntoIterator) -> Self { + let mut retval: Self = Default::default(); + for i in input { + retval.insert(i); + } + retval + } + + fn merge_node(&mut self, other: Self) -> bool { + let old_len = self.elements.len(); + self.elements.extend(other.elements); + self.elements.len() > old_len + } + + const HEIGHT: usize = 0; + + fn insert(&mut self, row: Self::Schema) -> bool { + self.elements.insert(row); + true + } + + fn contains<'a>(&'a self, row: ::AsRefVar<'a>) -> bool { + self.elements.iter().any(|r| Schema::eq_ref(r, row)) + } + + fn recursive_iter(&self) -> impl Iterator::AsRefVar<'_>> { + self.elements.iter() + } + + fn find_containing_leaf( + &self, + row: ::AsRefVar<'_>, + ) -> Option<&'_ GhtLeaf<::Schema, Self::ValType, Self::Storage>> + { + // TODO(mingwei): actually use the hash set as a hash set + if self + .elements + .iter() + .any(|x| ::eq_ref(row, x)) + { + Some(self) + } else { + None + } + } + + fn into_iter(self) -> Option> { + Some(self.elements.into_iter()) + } + + fn drain(&mut self) -> Option> { + Some(self.elements.drain()) + } +} + +impl GeneralizedHashTrieNode for GhtLeaf +where + Schema: 'static + Eq + VariadicExt + Hash + Clone + PartialEqVariadic, + Storage: VariadicCollection + Default + IntoIterator, +{ + type Schema = Schema; + type SuffixSchema = (); + type ValType = (); + type KeyType = Schema; + type Head = (); + type Storage = Storage; + + fn new_from(input: impl IntoIterator) -> Self { + let mut retval: Self = Default::default(); + for i in input { + retval.insert(i); + } + retval + } + + fn merge_node(&mut self, other: Self) -> bool { + let old_len = self.elements.len(); + self.elements.extend(other.elements); + self.elements.len() > old_len + } + + const HEIGHT: usize = 0; + + fn insert(&mut self, row: Self::Schema) -> bool { + self.elements.insert(row); + true + } + + fn contains<'a>(&'a self, row: ::AsRefVar<'a>) -> bool { + self.elements.iter().any(|r| Schema::eq_ref(r, row)) + } + + fn recursive_iter(&self) -> impl Iterator::AsRefVar<'_>> { + self.elements.iter() + } + + fn find_containing_leaf( + &self, + row: ::AsRefVar<'_>, + ) -> Option<&'_ GhtLeaf<::Schema, Self::ValType, Self::Storage>> + { + // TODO(mingwei): actually use the hash set as a hash set + if self + .elements + .iter() + .any(|x| ::eq_ref(row, x)) + { + Some(self) + } else { + None + } + } + + fn into_iter(self) -> Option> { + Some(self.elements.into_iter()) + } + + fn drain(&mut self) -> Option> { + Some(self.elements.drain()) + } +} + +impl FromIterator for GhtLeaf +where + Schema: Eq + Hash, + Storage: VariadicCollection + Default + FromIterator, +{ + fn from_iter>(iter: Iter) -> Self { + let elements = iter.into_iter().collect(); + Self { + elements, + forced: false, + _suffix_schema: PhantomData, + } + } +} + +/// A trait for the get and iter methods from Wang/Willsey/Suciu, which +/// work differently on leaves than internal nodes +pub trait GhtGet: GeneralizedHashTrieNode { + /// Type returned by [`Self::get`]. + type Get: GeneralizedHashTrieNode; + + /// On an Inner node, retrieves the value (child) associated with the given "head" key. + /// returns an `Option` containing a reference to the value if found, or `None` if not found. + /// On a Leaf node, returns None. + fn get<'a>(&'a self, head: &Self::Head) -> Option<&'a Self::Get>; + + /// get, but mutable output + fn get_mut<'a>(&'a mut self, head: &Self::Head) -> Option<&'a mut Self::Get>; + + /// Iterator for the "head" keys (from inner nodes) or nothing (from leaf nodes). + fn iter(&self) -> impl Iterator; + + /// Iterator for the tuples (from leaf nodes) or nothing (from inner nodes). + fn iter_tuples(&self) -> impl Iterator::AsRefVar<'_>>; +} + +impl GhtGet for GhtInner +where + Head: 'static + Eq + Hash + Clone, + Node: 'static + GeneralizedHashTrieNode, + Node::Schema: SplitBySuffix, +{ + /// Type returned by [`Self::get`]. + type Get = Node; + + /// On an Inner node, retrieves the value (child) associated with the given "head" key. + /// returns an `Option` containing a reference to the value if found, or `None` if not found. + /// On a Leaf node, returns None. + fn get<'a>(&'a self, head: &Self::Head) -> Option<&'a Self::Get> { + self.children.get(head) + } + + fn get_mut<'a>(&'a mut self, head: &Self::Head) -> Option<&'a mut Self::Get> { + self.children.get_mut(head) + } + + fn iter(&self) -> impl Iterator { + self.children.keys().cloned() + } + + fn iter_tuples(&self) -> impl Iterator::AsRefVar<'_>> { + std::iter::empty() + } +} + +impl GhtGet for GhtLeaf +where + Schema: 'static + Eq + Hash + Clone + PartialEqVariadic + SplitBySuffix, + ValType: Eq + Hash + Clone + PartialEqVariadic, + >::Prefix: Eq + Hash + Clone, + GhtLeaf: GeneralizedHashTrieNode, + Storage: VariadicCollection, +{ + /// Type returned by [`Self::get`]. + type Get = GhtLeaf; + + /// On an Inner node, retrieves the value (child) associated with the given "head" key. + /// returns an `Option` containing a reference to the value if found, or `None` if not found. + /// On a Leaf node, returns None. + fn get<'a>(&'a self, _head: &Self::Head) -> Option<&'a Self::Get> { + None + } + fn get_mut<'a>(&'a mut self, _head: &Self::Head) -> Option<&'a mut Self::Get> { + None + } + + fn iter(&self) -> impl Iterator { + std::iter::empty() + } + + fn iter_tuples(&self) -> impl Iterator::AsRefVar<'_>> { + self.elements.iter() + } +} + +/// A trait to iterate through the items in a Ght based on a prefix of the schema. +pub trait GhtPrefixIter { + /// the schema output + type Item: VariadicExt; + /// given a prefix, return an iterator through the items below + fn prefix_iter<'a>( + &'a self, + prefix: KeyPrefix, + ) -> impl Iterator::AsRefVar<'a>> + where + Self::Item: 'a; +} + +impl<'k, Head, Node, PrefixRest> GhtPrefixIter + for GhtInner +where + Head: Eq + Hash + Clone, + Node: GeneralizedHashTrieNode + GhtPrefixIter, +{ + type Item = >::Item; + fn prefix_iter<'a>( + &'a self, + prefix: var_type!(&'k Head, ...PrefixRest), + ) -> impl Iterator::AsRefVar<'a>> + where + Self::Item: 'a, + { + let var_args!(head, ...rest) = prefix; + self.children + .get(head) + .map(|node| node.prefix_iter(rest)) + .into_iter() + .flatten() + } +} +impl GhtPrefixIter for GhtInner +where + Self: GeneralizedHashTrieNode, + Head: Eq + Hash + Clone, + Node: GeneralizedHashTrieNode, +{ + type Item = ::Schema; + fn prefix_iter<'a>( + &'a self, + _prefix: var_type!(), + ) -> impl Iterator::AsRefVar<'a>> + where + Self::Item: 'a, + { + self.recursive_iter() + } +} + +impl GhtPrefixIter + for GhtLeaf +where + KeyPrefixRef: 'static + RefVariadic, + Schema: 'static + VariadicExt + Hash + Eq + SplitBySuffix, + ValType: VariadicExt, + ValType: Split, + KeyPrefixRef::UnRefVar: PartialEqVariadic, + Storage: 'static + VariadicCollection, +{ + type Item = Schema; + fn prefix_iter<'a>( + &'a self, + prefix: KeyPrefixRef, + ) -> impl Iterator::AsRefVar<'a>> + where + Self::Item: 'a, + { + self.elements.iter().filter(move |&row| { + let (_row_prefix, row_mid_suffix) = + >::split_by_suffix_ref(row); + let (row_mid, _row_suffix): (::AsRefVar<'_>, _) = + >::split_ref(row_mid_suffix); + ::eq_ref(prefix.unref_ref(), row_mid) + }) + } +} diff --git a/lattices/src/ght/test.rs b/lattices/src/ght/test.rs new file mode 100644 index 000000000000..e24238c2de34 --- /dev/null +++ b/lattices/src/ght/test.rs @@ -0,0 +1,943 @@ +//! Tests for the GHT code +#[cfg(test)] +mod tests { + use std::collections::HashSet; + + #[test] + fn basic_test() { + use variadics::var_expr; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + // Example usage + type MyTrie1 = GhtType!(u32, u32 => &'static str: VariadicCountedHashSet); + + fn ght_type() {} + ght_type::(); + + let htrie1 = MyTrie1::new_from(vec![var_expr!(42, 314, "hello")]); + assert!(htrie1.contains(var_expr!(&42, &314, &"hello"))); + assert_eq!(htrie1.recursive_iter().count(), 1); + + type MyTrie2 = GhtType!(u32 => u32: VariadicCountedHashSet); + let htrie2 = MyTrie2::new_from(vec![var_expr!(42, 314)]); + assert!(htrie2.contains(var_expr!(&42, &314))); + assert_eq!(htrie1.recursive_iter().count(), 1); + + type MyTrie3 = GhtType!(u32, u64, u16 => &'static str: VariadicCountedHashSet); + let htrie3 = MyTrie3::new_from(vec![ + var_expr!(123, 2, 5, "hello"), + var_expr!(50, 1, 1, "hi"), + var_expr!(5, 1, 7, "hi"), + var_expr!(5, 1, 7, "bye"), + ]); + assert!(htrie3.contains(var_expr!(&50, &1, &1, &"hi"))); + assert_eq!(htrie3.recursive_iter().count(), 4); + } + #[test] + fn test_ght_node_type_macro() { + use variadics::var_expr; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + // 0 => 1 + type LilTrie = GhtType!(() => u32: VariadicCountedHashSet); + let _j = LilTrie::default(); + let _l = LilTrie::new_from(vec![var_expr!(1)]); + + // 0 => >1 + type LilTrie2 = GhtType!(() => u32, u64: VariadicCountedHashSet); + let _l = LilTrie2::default(); + let _l = LilTrie2::new_from(vec![var_expr!(1, 1)]); + + // 1 => 0 + type KeyNoValTrie = GhtType!(u32 => (): VariadicCountedHashSet); + let l = KeyNoValTrie::new_from(vec![var_expr!(1)]); + let _: KeyNoValTrie = l; + + // 1 => 1 + type SmallTrie = GhtType!(u32 => &'static str: VariadicCountedHashSet); + type SmallKeyedTrie = GhtType!(u32 => &'static str: VariadicCountedHashSet); + let l = SmallTrie::new_from(vec![var_expr!(1, "hello")]); + let _: SmallKeyedTrie = l; + + // 1 => >1 + type SmallKeyLongValTrie = GhtType!(u32 => u64, u16, &'static str: VariadicCountedHashSet); + let _x = SmallKeyLongValTrie::new_from(vec![var_expr!(1, 999, 222, "hello")]); + + // >1 => 0 + type LongKeyNoValTrie = GhtType!(u32, u64 => (): VariadicCountedHashSet); + let l = LongKeyNoValTrie::new_from(vec![var_expr!(1, 999)]); + let _: LongKeyNoValTrie = l; + + // >1 => 1 + type LongKeySmallValTrie = GhtType!(u32, u16 => &'static str: VariadicCountedHashSet); + type LongKeySmallValKeyedTrie = GhtType!(u32, u16 => &'static str: VariadicCountedHashSet); + let x = LongKeySmallValTrie::new_from(vec![var_expr!(1, 314, "hello")]); + let _: LongKeySmallValKeyedTrie = x; + let _ = LongKeySmallValTrie::new_from(vec![var_expr!(1, 314, "hello")]); + + // >1 => >1 + type LongKeyLongValTrie = GhtType!(u32, u64 => u16, &'static str: VariadicCountedHashSet); + let _x = LongKeyLongValTrie::new_from(vec![var_expr!(1, 999, 222, "hello")]); + } + + #[test] + fn test_insert() { + use variadics::var_expr; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + type MyGht = GhtType!(u16, u32 => u64: VariadicCountedHashSet); + let mut htrie = MyGht::default(); + htrie.insert(var_expr!(42, 314, 43770)); + assert_eq!(htrie.recursive_iter().count(), 1); + assert_eq!(MyGht::HEIGHT, 2); + htrie.insert(var_expr!(42, 315, 43770)); + assert_eq!(htrie.recursive_iter().count(), 2); + htrie.insert(var_expr!(42, 314, 30619)); + assert_eq!(htrie.recursive_iter().count(), 3); + htrie.insert(var_expr!(43, 10, 600)); + assert_eq!(htrie.recursive_iter().count(), 4); + assert!(htrie.contains(var_expr!(&42, &314, &30619))); + assert!(htrie.contains(var_expr!(&42, &315, &43770))); + assert!(htrie.contains(var_expr!(&43, &10, &600))); + + type LongKeyLongValTrie = GhtType!(u32, u64 => u16, &'static str: VariadicCountedHashSet); + let mut htrie = LongKeyLongValTrie::new_from(vec![var_expr!(1, 999, 222, "hello")]); + htrie.insert(var_expr!(1, 999, 111, "bye")); + htrie.insert(var_expr!(1, 1000, 123, "cya")); + assert!(htrie.contains(var_expr!(&1, &999, &222, &"hello"))); + assert!(htrie.contains(var_expr!(&1, &999, &111, &"bye"))); + assert!(htrie.contains(var_expr!(&1, &1000, &123, &"cya"))); + } + + #[test] + fn test_scale() { + use variadics::var_expr; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + type MyGht = GhtType!(bool, usize, &'static str => i32: VariadicCountedHashSet); + let mut htrie = MyGht::new_from(vec![var_expr!(true, 1, "hello", -5)]); + assert_eq!(htrie.recursive_iter().count(), 1); + for i in 1..1000000 { + htrie.insert(var_expr!(true, 1, "hello", i)); + } + assert_eq!(htrie.recursive_iter().count(), 1000000); + } + + #[test] + fn test_contains() { + use variadics::{var_expr, VariadicExt}; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + type MyGht = GhtType!(u16, u32 => u64: VariadicCountedHashSet); + let htrie = MyGht::new_from(vec![var_expr!(42_u16, 314_u32, 43770_u64)]); + let x = var_expr!(&42, &314, &43770); + assert!(htrie.contains(x)); + assert!(htrie.contains(var_expr!(42, 314, 43770).as_ref_var())); + assert!(htrie.contains(var_expr!(&42, &314, &43770))); + assert!(!htrie.contains(var_expr!(42, 314, 30619).as_ref_var())); + assert!(!htrie.contains(var_expr!(&42, &315, &43770))); + assert!(!htrie.contains(var_expr!(&43, &314, &43770))); + } + + #[test] + fn test_get() { + use variadics::{var_expr, VariadicExt}; + + use crate::ght::{GeneralizedHashTrieNode, GhtGet}; + use crate::GhtType; + + type MyGht = GhtType!(u32, u32 => u32: VariadicCountedHashSet); + let ht_root = MyGht::new_from(vec![var_expr!(42, 314, 43770)]); + + let inner = ht_root.get(&42).unwrap(); + let t = inner.recursive_iter().next().unwrap(); + assert_eq!(t, var_expr!(&42, &314, &43770)); + + let leaf = inner.get(&314).unwrap(); + let t = leaf.recursive_iter().next().unwrap(); + assert_eq!(t, var_expr!(42, 314, 43770).as_ref_var()); + } + + #[test] + fn test_iter() { + use variadics::var_expr; + + use crate::ght::{GeneralizedHashTrieNode, GhtGet}; + use crate::GhtType; + type MyGht = GhtType!(u32, u32 => u32: VariadicCountedHashSet); + let ht_root = MyGht::new_from(vec![var_expr!(42, 314, 43770)]); + let inner_key = ht_root.iter().next().unwrap(); + let inner = ht_root.get(&inner_key).unwrap(); + let t = inner.recursive_iter().next().unwrap(); + assert_eq!(t, var_expr!(&42, &314, &43770)); + + let leaf_key = inner.iter().next().unwrap(); + let leaf = inner.get(&leaf_key).unwrap(); + // iter() on leaf should return None + let t = leaf.iter().next(); + assert!(t.is_none()); + } + + #[test] + fn test_recursive_iter() { + use variadics::{var_expr, var_type, VariadicExt}; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + type MyGht = GhtType!(u32, u32 => u32: VariadicCountedHashSet); + type InputType = var_type!(u32, u32, u32); + type ResultType<'a> = var_type!(&'a u32, &'a u32, &'a u32); + let input: HashSet = HashSet::from_iter( + [ + (42, 314, 30619), + (42, 314, 43770), + (42, 315, 43770), + (43, 10, 600), + ] + .iter() + .map(|&(a, b, c)| var_expr!(a, b, c)), + ); + let htrie = MyGht::new_from(input.clone()); + let result = input.iter().map(|v| v.as_ref_var()).collect(); + let v: HashSet = htrie.recursive_iter().collect(); + assert_eq!(v, result); + } + + #[test] + fn test_prefix_iter_leaf() { + use variadics::variadic_collections::VariadicCountedHashSet; + use variadics::{var_expr, var_type}; + + use crate::ght::{GeneralizedHashTrieNode, GhtLeaf, GhtPrefixIter}; + + type InputType = var_type!(u8, u16, u32); + type ResultType<'a> = var_type!(&'a u8, &'a u16, &'a u32); + + let input: HashSet = HashSet::from_iter( + [ + (42, 314, 30619), + (42, 314, 43770), + (42, 315, 43770), + (43, 10, 600), + ] + .iter() + .map(|&(a, b, c)| var_expr!(a, b, c)), + ); + let leaf = + GhtLeaf::>::new_from( + input.clone(), + ); + // let key = var_expr!(42u8).as_ref_var(); + let key = (); // (var_expr!().as_ref_var();) + let v: HashSet = leaf.prefix_iter(key).collect(); + let result = input + .iter() + // .filter(|t: &&InputType| t.0 == 42) + .map(|t: &InputType| var_expr!(&t.0, &t.1 .0, &t.1 .1 .0)) + .collect(); + assert_eq!(v, result); + } + + #[test] + fn test_prefix_iter() { + use variadics::{var_expr, var_type, VariadicExt}; + + use crate::ght::{GeneralizedHashTrieNode, GhtPrefixIter}; + use crate::GhtType; + + type MyGht = GhtType!(u8, u16 => u32: VariadicCountedHashSet); + type InputType = var_type!(u8, u16, u32); + type ResultType<'a> = var_type!(&'a u8, &'a u16, &'a u32); + let input: HashSet = HashSet::from_iter( + [ + (42, 314, 30619), + (42, 314, 43770), + (42, 315, 43770), + (43, 10, 600), + ] + .iter() + .map(|&(a, b, c)| var_expr!(a, b, c)), + ); + let htrie = MyGht::new_from(input.clone()); + + let v: HashSet = htrie.prefix_iter(var_expr!(42, 315).as_ref_var()).collect(); + let result = HashSet::from_iter([var_expr!(&42, &315, &43770)].iter().copied()); + assert_eq!(v, result); + + let v: HashSet = htrie.prefix_iter(var_expr!(42u8).as_ref_var()).collect(); + let result = input + .iter() + .filter(|t: &&InputType| t.0 == 42) + .map(|t: &InputType| var_expr!(&t.0, &t.1 .0, &t.1 .1 .0)) + .collect(); + assert_eq!(v, result); + + for row in htrie.prefix_iter(var_expr!(42, 315, 43770).as_ref_var()) { + assert_eq!(row, var_expr!(&42, &315, &43770)); + } + } + + #[test] + fn test_prefix_iter_complex() { + use variadics::{var_expr, var_type, VariadicExt}; + + use crate::ght::{GeneralizedHashTrieNode, GhtPrefixIter}; + use crate::GhtType; + + type MyGht = GhtType!(bool, u32, &'static str => i32: VariadicCountedHashSet); + type InputType = var_type!(bool, u32, &'static str, i32); + type ResultType<'a> = var_type!(&'a bool, &'a u32, &'a &'static str, &'a i32); + let input: HashSet = HashSet::from_iter( + [ + (true, 1, "hello", -5), + (true, 1, "hi", -2), + (true, 1, "hi", -3), + (true, 1, "hi", -4), + (true, 1, "hi", -5), + (true, 2, "hello", 1), + (false, 10, "bye", 5), + ] + .iter() + .map(|&(a, b, c, d)| var_expr!(a, b, c, d)), + ); + + let htrie = MyGht::new_from(input.clone()); + + let v: HashSet = htrie + .prefix_iter(var_expr!(true, 1, "hi").as_ref_var()) + .collect(); + let result = input + .iter() + .filter(|t: &&InputType| t.0 && t.1.0 == 1 && t.1.1.0 == "hi") + //.map(|t: &InputType| (&t.0, &t.1 .0, (&t.1 .1 .0, (&t.1 .1 .1 .0, ())))) + .map(|t| t.as_ref_var()) + .collect(); + assert_eq!(v, result); + + let v: HashSet = htrie.prefix_iter(var_expr!(true).as_ref_var()).collect(); + let result = input + .iter() + .filter(|t: &&InputType| t.0) + .map(|t: &InputType| t.as_ref_var()) + .collect(); + assert_eq!(v, result); + } + + #[test] + fn test_merge() { + use variadics::{var_expr, var_type}; + + use crate::ght::GeneralizedHashTrieNode; + use crate::{GhtType, Merge}; + + type MyGht = GhtType!(u32, u64 => u16, &'static str: VariadicHashSet); + + let mut test_ght1 = MyGht::new_from(vec![var_expr!(42, 314, 10, "hello")]); + let test_ght2 = MyGht::new_from(vec![var_expr!(42, 314, 10, "hello")]); + + assert_eq!( + test_ght1 + .recursive_iter() + .collect::>() + .len(), + 1 + ); + test_ght1.merge(test_ght2.clone()); + // merge does not contain duplicate copy of the tuple + assert_eq!( + test_ght1 + .recursive_iter() + .collect::>() + .len(), + 1 + ); + assert!(!test_ght1.merge(test_ght2.clone())); + + let mut test_ght1 = MyGht::new_from(vec![var_expr!(42, 314, 10, "hello")]); + let mut test_ght2 = MyGht::new_from(vec![var_expr!(42, 314, 10, "hello")]); + test_ght1.merge(test_ght2.clone()); + + test_ght1.insert(var_expr!(42, 314, 20, "goodbye")); + test_ght2.insert(var_expr!(42, 314, 20, "again")); + + // change on merge + assert!(test_ght1.merge(test_ght2.clone())); + for k in test_ght2.recursive_iter() { + assert!(test_ght1.contains(k)) + } + } + + #[test] + fn test_node_lattice() { + use variadics::var_expr; + + use crate::ght::GeneralizedHashTrieNode; + use crate::{GhtType, NaiveLatticeOrd}; + + type MyGht = GhtType!(u32, u64 => u16, &'static str: VariadicHashSet); + type MyGhtNode = GhtType!(u32, u64 => u16, &'static str: VariadicHashSet); + + let mut test_vec: Vec = Vec::new(); + + let empty_ght = MyGht::new_from(vec![]); + let test_ght1 = MyGht::new_from(vec![var_expr!(42, 314, 10, "hello")]); + let mut test_ght2 = MyGht::new_from(vec![var_expr!(42, 314, 10, "hello")]); + test_ght2.insert(var_expr!(42, 314, 20, "again")); + let mut test_ght3 = test_ght2.clone(); + test_ght3.insert(var_expr!(42, 400, 1, "level 2")); + let mut test_ght4 = test_ght3.clone(); + test_ght4.insert(var_expr!(43, 1, 1, "level 1")); + + let test_vec_wrap = [empty_ght, test_ght1, test_ght2, test_ght3, test_ght4]; + + for ght in test_vec_wrap.iter().cloned() { + ght.naive_cmp(&ght.clone()); + test_vec.push(ght); + } + crate::test::check_all(&test_vec); + crate::test::check_all(&test_vec_wrap); + } + + #[test] + fn test_cartesian_bimorphism() { + use variadics::var_expr; + + use crate::ght::lattice::GhtCartesianProductBimorphism; + use crate::ght::GeneralizedHashTrieNode; + use crate::{GhtType, LatticeBimorphism}; + + type MyGhtA = GhtType!(u32, u64 => u16, &'static str: VariadicHashSet); + type MyGhtB = GhtType!(u32, u64, u16 => &'static str: VariadicHashSet); + + let mut ght_a = MyGhtA::default(); + let mut ght_b = MyGhtB::default(); + + ght_a.insert(var_expr!(123, 2, 5, "hello")); + ght_a.insert(var_expr!(50, 1, 1, "hi")); + ght_a.insert(var_expr!(5, 1, 7, "hi")); + ght_b.insert(var_expr!(5, 1, 8, "hi")); + ght_b.insert(var_expr!(10, 1, 2, "hi")); + ght_b.insert(var_expr!(12, 10, 98, "bye")); + + type MyGhtAb = GhtType!(u32, u64, u16, &'static str, u32, u64 => u16, &'static str: VariadicCountedHashSet); + + let mut bim = GhtCartesianProductBimorphism::::default(); + let ght_out = bim.call(&ght_a, &ght_b); + assert_eq!( + ght_out.recursive_iter().count(), + ght_a.recursive_iter().count() * ght_b.recursive_iter().count() + ); + } + + #[test] + fn test_join_bimorphism() { + use variadics::variadic_collections::{VariadicCountedHashSet, VariadicHashSet}; + use variadics::{var_expr, var_type}; + + use crate::ght::lattice::{ + DeepJoinLatticeBimorphism, GhtNodeKeyedBimorphism, GhtValTypeProductBimorphism, + }; + use crate::ght::{GeneralizedHashTrieNode, GhtInner, GhtLeaf}; + use crate::{GhtType, LatticeBimorphism}; + + type ResultSchemaType = var_type!(u32, u64, u16, &'static str, &'static str); + type ResultSchemaRefType<'a> = var_type!( + &'a u32, + &'a u64, + &'a u16, + &'a &'static str, + &'a &'static str + ); + type MyGhtATrie = GhtType!(u32, u64, u16 => &'static str: VariadicHashSet); + type MyGhtBTrie = GhtType!(u32, u64, u16 => &'static str: VariadicHashSet); + + let mut ght_a = MyGhtATrie::default(); + let mut ght_b = MyGhtBTrie::default(); + + ght_a.insert(var_expr!(123, 2, 5, "hello")); + ght_a.insert(var_expr!(50, 1, 1, "hi")); + ght_a.insert(var_expr!(5, 1, 7, "hi")); + + ght_b.insert(var_expr!(5, 1, 8, "hi")); + ght_b.insert(var_expr!(5, 1, 7, "world")); + ght_b.insert(var_expr!(10, 1, 2, "hi")); + ght_b.insert(var_expr!(12, 10, 98, "bye")); + + let result: HashSet = [var_expr!(&5, &1, &7, &"hi", &"world")] + .iter() + .copied() + .collect(); + { + // here we manually construct the proper bimorphism stack. + // note that the bottommost bimorphism is GhtValTypeProductBimorphism, + // which ensures that the Schema of the resulting output GhtLeaf and GhtInner + // nodes correctly includes the key columns, not just the cross-product of the values. + type MyGhtOut = GhtInner< + &'static str, + GhtLeaf< + ResultSchemaType, + var_type!(&'static str), + VariadicCountedHashSet, + >, + >; + // let mut bim = GhtNodeKeyedBimorphism::new(GhtNodeKeyedBimorphism::new( + // GhtNodeKeyedBimorphism::new(GhtValTypeProductBimorphism::::default()), + // )); + let mut bim = GhtNodeKeyedBimorphism::new(GhtNodeKeyedBimorphism::new( + GhtNodeKeyedBimorphism::new(GhtValTypeProductBimorphism::::default()), + )); + let out = bim.call(&ght_a, &ght_b); + let out: HashSet = out.recursive_iter().collect(); + assert_eq!(out, result.iter().copied().collect()); + } + { + // Here we use DeepJoinLatticeBimorphism as a more compact representation of the + // manual stack of bimorphisms above. This is the recommended approach. + type MyNodeBim<'a> = <(MyGhtATrie, MyGhtBTrie) as DeepJoinLatticeBimorphism< + VariadicHashSet, + >>::DeepJoinLatticeBimorphism; + let mut bim = ::default(); + let out = bim.call(&ght_a, &ght_b); + let out: HashSet = out.recursive_iter().collect(); + assert_eq!(out, result.iter().copied().collect()); + } + } + + #[test] + fn test_ght_with_tuple_macro() { + use variadics::{var_expr, VariadicExt}; + use variadics_macro::tuple; + + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + type MyRoot = GhtType!(u16, u32 => u64: VariadicCountedHashSet); + + let mut trie1 = MyRoot::default(); + assert_eq!(3, <::Schema>::LEN); + trie1.insert(var_expr!(1, 2, 3)); + let t = trie1.recursive_iter().next().unwrap(); + let tup = tuple!(t, 3); + assert_eq!(tup, (&1, &2, &3)); + } + + #[test] + fn test_triangle_generic_join() { + use std::hash::{BuildHasherDefault, DefaultHasher}; + + use variadics::var_expr; + + use crate::ght::{GeneralizedHashTrieNode, GhtPrefixIter}; + use crate::GhtType; + + const MATCHES: u32 = 1000; + type MyGht = GhtType!(u32 => u32: VariadicCountedHashSet); + + let r_iter = (0..MATCHES) + .map(|i| (0, i)) + .chain((1..MATCHES).map(|i| (i, 0))); + + let s_iter = (0..MATCHES) + .map(|i| (0, i)) + .chain((1..MATCHES).map(|i| (i, 0))); + + let t_iter = (0..MATCHES) + .map(|i| (0, i)) + .chain((1..MATCHES).map(|i| (i, 0))); + + let rx_ght = MyGht::new_from(r_iter.clone().map(|(x, y)| var_expr!(x, y))); + let sb_ght = MyGht::new_from(s_iter.clone().map(|(y, b)| var_expr!(b, y))); + let tx_ght = MyGht::new_from(t_iter.clone().map(|(z, x)| var_expr!(x, z))); + + let r_x = r_iter + .clone() + .map(|(x, _y)| x) + .collect::>>(); + let t_x = s_iter + .clone() + .map(|(_z, x)| x) + .collect::>>(); + let x_inter = r_x.intersection(&t_x); + let len = x_inter.clone().count(); + if len > 1 { + assert_eq!(1000, len); + } + + let mut output: Vec<(u32, u32, u32)> = Vec::new(); + let mut x_iters = 0usize; + let mut y_iters = 0usize; + let mut z_iters = 0usize; + for a in x_inter { + x_iters += 1; + let r = rx_ght + .prefix_iter(var_expr!(a)) + .map(|(_x, (y, ()))| *y) + .collect::>>(); + let s_y = s_iter + .clone() + .map(|(y, _z)| y) + .collect::>>(); + let y_inter = r.intersection(&s_y); + let len = y_inter.clone().count(); + if len > 1 { + assert_eq!(1000, len); + } + for b in y_inter { + y_iters += 1; + let s = sb_ght + .prefix_iter(var_expr!(b)) + .map(|(_b, (z, ()))| *z) + .collect::>>(); + let t = tx_ght + .prefix_iter(var_expr!(a)) + .map(|(_x, (z, ()))| *z) + .collect::>>(); + let z_inter = s.intersection(&t); + let len = z_inter.clone().count(); + if len > 1 { + assert_eq!(1000, len); + } + for c in z_inter { + z_iters += 1; + output.push((*a, *b, *c)); + } + } + } + + assert_eq!(1000, x_iters); + assert_eq!(1999, y_iters); + assert_eq!(2998, z_iters); + assert_eq!(2998, output.len()); + } + + fn clover_setup( + matches: usize, + ) -> ( + impl Iterator, + impl Iterator, + impl Iterator, + ) { + let r_iter = (1..matches) + .map(|i| (1u32, i as u32)) + .chain((1..matches).map(|i| (2, i as u32))) + .chain([(0, 0)]); + + let s_iter = (1..matches) + .map(|i| (2u32, i as u32)) + .chain((1..matches).map(|i| (3, i as u32))) + .chain([(0, 0)]); + + let t_iter = (1..matches) + .map(|i| (3u32, i as u32)) + .chain((1..matches).map(|i| (1, i as u32))) + .chain([(0, 0)]); + (r_iter, s_iter, t_iter) + } + + #[test] + fn clover_generic_join() { + use variadics::var_expr; + + use crate::ght::{GeneralizedHashTrieNode, GhtGet}; + use crate::GhtType; + + const MATCHES: usize = 1000; + let (r_iter, s_iter, t_iter) = clover_setup(MATCHES); + + type MyGht = GhtType!(u32 => u32: VariadicCountedHashSet); + let rx_ght = MyGht::new_from(r_iter.map(|(x, a)| var_expr!(x, a))); + let sx_ght = MyGht::new_from(s_iter.map(|(x, b)| var_expr!(x, b))); + let tx_ght = MyGht::new_from(t_iter.map(|(x, c)| var_expr!(x, c))); + for x in rx_ght.iter() { + if let (Some(r), Some(s), Some(t)) = (rx_ght.get(&x), sx_ght.get(&x), tx_ght.get(&x)) { + // All unwraps succeeded, use `r`, `s`, `t` here + for a in r.iter() { + for b in s.iter() { + for c in t.iter() { + assert_eq!((x, a, b, c), (0, 0, 0, 0)); + } + } + } + } else { + // If any unwrap fails, continue to the next iteration + continue; + } + } + } + + #[test] + fn clover_factorized_join() { + use variadics::var_expr; + + use crate::ght::{GeneralizedHashTrieNode, GhtGet}; + use crate::GhtType; + + const MATCHES: usize = 1000; + let (r_iter, s_iter, t_iter) = clover_setup(MATCHES); + + type Ght1 = GhtType!(() => u32, u32: VariadicCountedHashSet); + type Ght2 = GhtType!(u32 => u32: VariadicCountedHashSet); + let rx_ght = Ght1::new_from(r_iter.map(|(x, a)| var_expr!(x, a))); + let sx_ght = Ght2::new_from(s_iter.map(|(x, b)| var_expr!(x, b))); + let tx_ght = Ght2::new_from(t_iter.map(|(x, c)| var_expr!(x, c))); + + for t in rx_ght.recursive_iter() { + let (x, (a, ())): (&u32, (&u32, _)) = t; + if let (Some(s), Some(t)) = (sx_ght.get(x), tx_ght.get(x)) { + // All unwraps succeeded, use `s`, `t` here + for b in s.iter() { + for c in t.iter() { + assert_eq!((x, a, b, c), (&0, &0, 0, 0)); + } + } + } else { + // If any unwrap fails, continue to the next iteration + continue; + } + } + } + + #[test] + fn test_force() { + use variadics::var_expr; + + use crate::ght::colt::ColtForestNode; + use crate::ght::GeneralizedHashTrieNode; + use crate::GhtType; + + type LeafType = GhtType!(() => u16, u32, u64: VariadicCountedHashSet); + let n = LeafType::new_from(vec![ + var_expr!(1, 1, 1), + var_expr!(1, 2, 2), + var_expr!(1, 3, 3), + var_expr!(2, 4, 4), + ]); + let out = n.force().unwrap(); + assert_eq!(out.height(), 1); + } + + #[test] + fn test_forest_macro() { + use crate::ColtType; + + type Forest4 = ColtType!(u8, u16, u32, u64); + let _f4 = Forest4::default(); + + type Forest3 = ColtType!(u8, u16, u32); + let _f3 = Forest3::default(); + + type Forest2 = ColtType!(u8, u16); + let _f2 = Forest2::default(); + + type Forest1 = ColtType!(u8); + let _f2 = Forest1::default(); + + type Forest01 = ColtType!(() => u16); + let _f01 = Forest01::default(); + + type Forest02 = ColtType!(() => u8, u16); + let _f02 = Forest02::default(); + + type Forest10 = ColtType!(u8 => ()); + let _f10 = Forest10::default(); + + type Forest11 = ColtType!(u8 => u16); + let _f11 = Forest11::default(); + + type Forest12 = ColtType!(u8 => u16, u32); + let _f12 = Forest12::default(); + + type Forest20 = ColtType!(u8, u16 => ()); + let _f20 = Forest20::default(); + + type Forest21 = ColtType!(u8, u16 => u32); + let _f21 = Forest21::default(); + + type Forest22 = ColtType!(u8, u16 => u32, u64); + let _f22 = Forest22::default(); + } + + #[test] + fn test_colt_little_get() { + use variadics::variadic_collections::VariadicCollection; + use variadics::{var_expr, VariadicExt}; + + use crate::ght::colt::ColtGet; + use crate::ght::GeneralizedHashTrieNode; + use crate::ColtType; + + type MyForest = ColtType!(u8); + + let mut forest = MyForest::default(); + + forest.0.insert(var_expr!(1)); + forest.0.insert(var_expr!(2)); + forest.0.insert(var_expr!(3)); + + assert_eq!(2, forest.len()); + assert_eq!(3, forest.0.elements.len()); + + let result = ColtGet::get(forest.as_mut_var(), &3); + assert_eq!(1, result.len()); + assert_eq!(0, forest.0.elements.len()); + assert!(forest.0.forced); + } + + #[test] + fn test_colt_get() { + use variadics::variadic_collections::VariadicCollection; + use variadics::{var_expr, VariadicExt}; + + use crate::ght::colt::ColtGet; + use crate::ght::{GeneralizedHashTrieNode, GhtGet}; + use crate::ColtType; + + type MyForest = ColtType!(u8, u16, u32, u64); + let mut forest = MyForest::default(); + forest.0.insert(var_expr!(1, 1, 1, 1)); + forest.0.insert(var_expr!(2, 2, 2, 2)); + forest.0.insert(var_expr!(3, 3, 3, 3)); + + let len = forest.len(); + assert_eq!(5, len); + { + let get_result = ColtGet::get(forest.as_mut_var(), &1); + assert_eq!(get_result.len(), len - 1); + assert_eq!(get_result.0.height(), 0); + let get_result2 = ColtGet::get(get_result, &1); + assert_eq!(get_result2.len(), len - 2); + let get_result3 = ColtGet::get(get_result2, &1); + assert_eq!(get_result3.len(), len - 3); + assert_eq!( + get_result3.0.elements.iter().next(), + Some(var_expr!(1, 1, 1, 1).as_ref_var()) + ); + assert_eq!(get_result3.1 .0.children.len(), 0); + } + { + let get_result = ColtGet::get(forest.as_mut_var(), &3); + assert_eq!(get_result.len(), len - 1); + let get_result2 = ColtGet::get(get_result, &3); + assert_eq!(get_result2.len(), len - 2); + assert_eq!( + get_result2.0.elements.iter().next(), + Some(var_expr!(3, 3, 3, 3).as_ref_var()) + ); + assert_eq!(get_result2.1 .0.children.len(), 0); + } + assert!(forest.0.forced); + assert_eq!(3, forest.1 .0.children.len()); // keys 1, 2 and 3 + assert_eq!(0, forest.1 .0.get(&1).unwrap().elements.len()); + assert_eq!(1, forest.1 .0.get(&2).unwrap().elements.len()); + assert_eq!(0, forest.1 .0.get(&3).unwrap().elements.len()); + assert_eq!(2, forest.1 .1 .0.children.len()); // keys 1 and 3 + assert_eq!( + 0, + forest + .1 + .1 + .0 + .get(&1) + .unwrap() + .get(&1) + .unwrap() + .elements + .len() + ); + assert!(forest.1 .1 .0.get(&2).is_none()); + assert_eq!( + 1, + forest + .1 + .1 + .0 + .get(&3) + .unwrap() + .get(&3) + .unwrap() + .elements + .len() + ); + assert_eq!( + 1, + forest + .1 + .1 + .1 + .0 + .get(&1) + .unwrap() + .get(&1) + .unwrap() + .get(&1) + .unwrap() + .elements + .len() + ); + } + + #[test] + fn test_colt_scale() { + use variadics::variadic_collections::VariadicCollection; + use variadics::{var_expr, VariadicExt}; + + use crate::ght::colt::ColtGet; + use crate::ght::{GeneralizedHashTrieNode, GhtPrefixIter}; + + type MyColt = crate::ColtType!(i32, bool, usize, &'static str); + let mut forest = MyColt::default(); + for i in 1..100000 { + forest.0.insert(var_expr!(i, true, 1, "hello")); + } + { + let result = forest.as_mut_var().get(&3); + assert_eq!(result.len(), 4); + } + // check: first Leaf trie is forced + assert!(forest.0.forced); + assert_eq!(forest.0.elements.len(), 0); + { + let result = forest.as_mut_var().get(&3); + let result2 = result.get(&true); + assert_eq!(result2.len(), 3); + } + { + // check: leaf below 3 in first non-empty trie is forced + let result = forest.as_mut_var().get(&3); + assert!(result.0.forced); + assert_eq!(result.0.elements.len(), 0); + } + // check: prefix (3, true) is now found in the third trie: forest.1.1.0 + assert!(forest + .1 + .1 + .0 + .prefix_iter(var_expr!(3, true).as_ref_var()) + .next() + .is_some()); + { + let result = forest.as_mut_var().get(&3); + let result2 = result.get(&true); + assert_eq!(result2.len(), 3); + let result3 = result2.get(&1); + assert_eq!(result3.len(), 2); + let result4 = result3.get(&"hello"); + assert_eq!(result4.0.elements.len(), 1); + assert_eq!( + result4.0.elements.iter().next(), + Some(var_expr!(3, true, 1, "hello").as_ref_var()) + ); + } + } +} diff --git a/lattices/src/lib.rs b/lattices/src/lib.rs index c8fc0804819e..bac63c543b16 100644 --- a/lattices/src/lib.rs +++ b/lattices/src/lib.rs @@ -3,14 +3,15 @@ use std::cmp::Ordering::{self, *}; -pub use cc_traits; use sealed::sealed; +pub use {cc_traits, variadics}; /// Module for definiting algebraic structures and properties. pub mod algebra; pub mod collections; mod conflict; mod dom_pair; +pub mod ght; pub mod map_union; pub mod map_union_with_tombstones; mod ord; diff --git a/lattices/src/test.rs b/lattices/src/test.rs index 2b2068906c46..80306c7752ad 100644 --- a/lattices/src/test.rs +++ b/lattices/src/test.rs @@ -329,8 +329,8 @@ pub fn cartesian_power( (size, Some(size)) } } - impl<'a, T, const N: usize> ExactSizeIterator for CartesianPower<'a, T, N> {} - impl<'a, T, const N: usize> Clone for CartesianPower<'a, T, N> { + impl ExactSizeIterator for CartesianPower<'_, T, N> {} + impl Clone for CartesianPower<'_, T, N> { fn clone(&self) -> Self { Self { items: self.items, diff --git a/lattices/src/vec_union.rs b/lattices/src/vec_union.rs index 731f6009711f..e9ef26994348 100644 --- a/lattices/src/vec_union.rs +++ b/lattices/src/vec_union.rs @@ -98,13 +98,13 @@ where { fn eq(&self, other: &VecUnion) -> bool { if self.vec.len() != other.vec.len() { - return false; + false + } else { + self.vec + .iter() + .zip(other.vec.iter()) + .all(|(val_self, val_other)| val_self == val_other) } - return self - .vec - .iter() - .zip(other.vec.iter()) - .all(|(val_self, val_other)| val_self == val_other); } } diff --git a/lattices/tests/compile-fail/non_lattice_field.stderr b/lattices/tests/compile-fail/non_lattice_field.stderr index f2630b97f64e..7b8e66201e53 100644 --- a/lattices/tests/compile-fail/non_lattice_field.stderr +++ b/lattices/tests/compile-fail/non_lattice_field.stderr @@ -8,11 +8,11 @@ error[E0277]: the trait bound `String: Merge` is not satisfied `()` implements `Merge<()>` `Conflict` implements `Merge>` `DomPair` implements `Merge>` + `GhtInner` implements `Merge>` + `GhtLeaf` implements `Merge>` `MapUnion` implements `Merge>` `MapUnionWithTombstones` implements `Merge>` `Max` implements `Merge>` - `Min` implements `Merge>` - `NotALattice` implements `Merge` and $N others = help: see issue #48214 = note: this error originates in the derive macro `Lattice` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -31,11 +31,11 @@ error[E0277]: the trait bound `String: IsBot` is not satisfied () Conflict DomPair + GhtInner + GhtLeaf MapUnion MapUnionWithTombstones Max<()> - Max - Max and $N others = help: see issue #48214 = note: this error originates in the derive macro `Lattice` (in Nightly builds, run with -Z macro-backtrace for more info) @@ -54,11 +54,11 @@ error[E0277]: the trait bound `String: IsTop` is not satisfied () Conflict DomPair + GhtInner + GhtLeaf MapUnion MapUnionWithTombstones Max<()> - Max - Max and $N others = help: see issue #48214 = note: this error originates in the derive macro `Lattice` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/stageleft/src/lib.rs b/stageleft/src/lib.rs index ff23a4c4963c..d0b40c64d1ee 100644 --- a/stageleft/src/lib.rs +++ b/stageleft/src/lib.rs @@ -102,7 +102,7 @@ pub struct BorrowBounds<'a> { _marker: PhantomData<&'a &'a mut ()>, } -impl<'a> QuotedContext for BorrowBounds<'a> { +impl QuotedContext for BorrowBounds<'_> { fn create() -> Self { BorrowBounds { _marker: PhantomData, @@ -242,9 +242,8 @@ impl< } impl< - 'a, T, - F: FnOnce(&mut String, &mut &'static str, &mut TokenStream, &mut CaptureVec, bool) -> T + 'a, + F: FnOnce(&mut String, &mut &'static str, &mut TokenStream, &mut CaptureVec, bool) -> T, > FreeVariable for F { fn to_tokens(self) -> (Option, Option) { diff --git a/variadics/src/lib.rs b/variadics/src/lib.rs index bd0de27a1a3f..ad08b9fe0a9b 100644 --- a/variadics/src/lib.rs +++ b/variadics/src/lib.rs @@ -209,7 +209,10 @@ where { const LEN: usize = 1 + Rest::LEN; - type Extend = (Item, Rest::Extend) where Suffix: VariadicExt; + type Extend + = (Item, Rest::Extend) + where + Suffix: VariadicExt; fn extend(self, suffix: Suffix) -> Self::Extend where Suffix: VariadicExt, @@ -232,7 +235,8 @@ where out2 } - type AsRefVar<'a> = (&'a Item, Rest::AsRefVar<'a>) + type AsRefVar<'a> + = (&'a Item, Rest::AsRefVar<'a>) where Self: 'a; fn as_ref_var(&self) -> Self::AsRefVar<'_> { @@ -240,7 +244,8 @@ where (item, rest.as_ref_var()) } - type AsMutVar<'a> = (&'a mut Item, Rest::AsMutVar<'a>) + type AsMutVar<'a> + = (&'a mut Item, Rest::AsMutVar<'a>) where Self: 'a; fn as_mut_var(&mut self) -> Self::AsMutVar<'_> { @@ -248,7 +253,8 @@ where (item, rest.as_mut_var()) } - type IterAnyRef<'a> = std::iter::Chain, Rest::IterAnyRef<'a>> + type IterAnyRef<'a> + = std::iter::Chain, Rest::IterAnyRef<'a>> where Self: 'static; fn iter_any_ref(&self) -> Self::IterAnyRef<'_> @@ -260,7 +266,8 @@ where std::iter::once(item).chain(rest.iter_any_ref()) } - type IterAnyMut<'a> = std::iter::Chain, Rest::IterAnyMut<'a>> + type IterAnyMut<'a> + = std::iter::Chain, Rest::IterAnyMut<'a>> where Self: 'static; fn iter_any_mut(&mut self) -> Self::IterAnyMut<'_> @@ -289,7 +296,10 @@ where impl VariadicExt for () { const LEN: usize = 0; - type Extend = Suffix where Suffix: VariadicExt; + type Extend + = Suffix + where + Suffix: VariadicExt; fn extend(self, suffix: Suffix) -> Self::Extend where Suffix: VariadicExt, @@ -307,7 +317,8 @@ impl VariadicExt for () { type AsMutVar<'a> = (); fn as_mut_var(&mut self) -> Self::AsMutVar<'_> {} - type IterAnyRef<'a> = std::iter::Empty<&'a dyn Any> + type IterAnyRef<'a> + = std::iter::Empty<&'a dyn Any> where Self: 'static; fn iter_any_ref(&self) -> Self::IterAnyRef<'_> @@ -317,7 +328,8 @@ impl VariadicExt for () { std::iter::empty() } - type IterAnyMut<'a> = std::iter::Empty<&'a mut dyn Any> + type IterAnyMut<'a> + = std::iter::Empty<&'a mut dyn Any> where Self: 'static; fn iter_any_mut(&mut self) -> Self::IterAnyMut<'_> @@ -820,7 +832,10 @@ where std::iter::zip(this, rest.into_zip()) } - type Drain<'a> = std::iter::Zip, Rest::Drain<'a>> where Self: 'a; + type Drain<'a> + = std::iter::Zip, Rest::Drain<'a>> + where + Self: 'a; fn drain(&mut self, range: R) -> Self::Drain<'_> where R: std::ops::RangeBounds + Clone, @@ -849,7 +864,10 @@ impl VecVariadic for var_type!() { std::iter::repeat(var_expr!()) } - type Drain<'a> = std::iter::Repeat where Self: 'a; + type Drain<'a> + = std::iter::Repeat + where + Self: 'a; fn drain(&mut self, _range: R) -> Self::Drain<'_> where R: std::ops::RangeBounds, diff --git a/variadics/src/variadic_collections.rs b/variadics/src/variadic_collections.rs index 1a1fa28b6de6..5dcc8fb923a4 100644 --- a/variadics/src/variadic_collections.rs +++ b/variadics/src/variadic_collections.rs @@ -6,7 +6,7 @@ use hashbrown::hash_table::{Entry, HashTable}; use crate::{PartialEqVariadic, VariadicExt, VecVariadic}; /// Trait for a set of Variadic Tuples -pub trait VariadicCollection { +pub trait VariadicCollection: Extend { /// The Schema (aka Variadic type) associated with tuples in this set type Schema: PartialEqVariadic; @@ -58,7 +58,7 @@ impl Default for VariadicHashSet { impl fmt::Debug for VariadicHashSet where - T: fmt::Debug + VariadicExt + PartialEqVariadic, + T: fmt::Debug + VariadicExt + PartialEqVariadic + Eq + Hash, for<'a> T::AsRefVar<'a>: Hash + fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -82,7 +82,7 @@ where } impl VariadicCollection for VariadicHashSet where - T: VariadicExt + PartialEqVariadic, + T: VariadicExt + PartialEqVariadic + Eq + Hash, for<'a> T::AsRefVar<'a>: Hash, S: BuildHasher, { @@ -127,7 +127,7 @@ where } impl VariadicSet for VariadicHashSet where - T: VariadicExt + PartialEqVariadic, + T: VariadicExt + PartialEqVariadic + Eq + Hash, for<'a> T::AsRefVar<'a>: Hash, S: BuildHasher, { @@ -283,7 +283,7 @@ where impl VariadicCollection for VariadicCountedHashSet where - K: VariadicExt + PartialEqVariadic + Hash + Clone, + K: VariadicExt + PartialEqVariadic + Eq + Hash + Clone, for<'a> K::AsRefVar<'a>: Hash, S: BuildHasher, { @@ -333,7 +333,7 @@ where impl VariadicMultiset for VariadicCountedHashSet where - K: VariadicExt + PartialEqVariadic + Hash + Clone, + K: VariadicExt + PartialEqVariadic + Eq + Hash + Clone, for<'a> K::AsRefVar<'a>: Hash, S: BuildHasher, { @@ -356,6 +356,7 @@ where } /// Iterator helper for [`VariadicCountedHashSet::into_iter`]. +#[derive(Clone)] pub struct DuplicateCounted { iter: Iter, state: Option<(Item, usize)>, @@ -474,9 +475,10 @@ where /// Column storage for Variadic tuples of type Schema /// An alternative to VariadicHashMultiset +#[derive(Clone)] pub struct VariadicColumnMultiset where - Schema: VariadicExt, + Schema: VariadicExt + Eq + Hash, { columns: Schema::IntoVec, last_offset: usize, @@ -484,7 +486,7 @@ where impl VariadicColumnMultiset where - T: VariadicExt, + T: VariadicExt + Eq + Hash, { /// initialize an empty columnar multiset pub fn new() -> Self { @@ -497,7 +499,7 @@ where impl Default for VariadicColumnMultiset where - T: VariadicExt, + T: VariadicExt + Eq + Hash, { fn default() -> Self { Self::new() @@ -506,7 +508,8 @@ where impl VariadicCollection for VariadicColumnMultiset where - Schema: PartialEqVariadic, + Schema: PartialEqVariadic + Eq + Hash, + for<'a> ::AsRefVar<'a>: Hash, { type Schema = Schema; @@ -543,11 +546,16 @@ where } } -impl VariadicMultiset for VariadicColumnMultiset where Schema: PartialEqVariadic {} +impl VariadicMultiset for VariadicColumnMultiset +where + Schema: PartialEqVariadic + Eq + Hash, + for<'a> ::AsRefVar<'a>: Hash, +{ +} impl fmt::Debug for VariadicColumnMultiset where - T: fmt::Debug + VariadicExt + PartialEqVariadic, + T: fmt::Debug + VariadicExt + PartialEqVariadic + Eq + Hash, for<'a> T::AsRefVar<'a>: Hash + fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -557,7 +565,7 @@ where impl IntoIterator for VariadicColumnMultiset where - Schema: PartialEqVariadic, + Schema: PartialEqVariadic + Eq + Hash, { type Item = Schema; type IntoIter = ::IntoZip; diff --git a/variadics/tests/boxed_refed.rs b/variadics/tests/boxed_refed.rs index 17366b177dc5..8d7e44fc9f5c 100644 --- a/variadics/tests/boxed_refed.rs +++ b/variadics/tests/boxed_refed.rs @@ -29,7 +29,8 @@ impl Refed for (Item, Rest) where Rest: Refed, { - type Refed<'a> = (&'a Item, Rest::Refed<'a>) + type Refed<'a> + = (&'a Item, Rest::Refed<'a>) where Self: 'a; fn refed(&self) -> Self::Refed<'_> { diff --git a/variadics_macro/CHANGELOG.md b/variadics_macro/CHANGELOG.md new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/variadics_macro/Cargo.toml b/variadics_macro/Cargo.toml new file mode 100644 index 000000000000..2c8ef8b0944c --- /dev/null +++ b/variadics_macro/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "variadics_macro" +publish = true +version = "0.5.5" +edition = "2021" +license = "Apache-2.0" +documentation = "https://docs.rs/variadics/" +description = "Procedural macros for the `variadics` crate." + +[lib] +proc-macro = true + +[dependencies] +proc-macro2 = "1.0.63" +proc-macro-crate = "1.1.0" +quote = "1.0.0" +syn = { version = "2.0.0", features = [ "full", "parsing", "visit-mut" ] } +variadics = { path = "../variadics", version = "^0.0.6" } + +[dev-dependencies] +insta = "1.7.1" +prettyplease = "0.2.20" diff --git a/variadics_macro/README.md b/variadics_macro/README.md new file mode 100644 index 000000000000..5f2c0e520895 --- /dev/null +++ b/variadics_macro/README.md @@ -0,0 +1,17 @@ +## `tuple!` Macro + +Create a tuple from a Variadic type known at compile time. + +Example usage: +```rust +use variadics::var_expr; +use variadics_macro::tuple; + +let tup = var_expr!(1, 2, 3, "four"); +let a = tuple!(tup, 4); +assert_eq!(a, (1, 2, 3, "four")); + +let tup = var_expr!(1, 2, var_expr!(3)); +let b = tuple!(tup, 3); +assert_eq!(b, (1, 2, (3, ()))); +``` \ No newline at end of file diff --git a/variadics_macro/src/lib.rs b/variadics_macro/src/lib.rs new file mode 100644 index 000000000000..2583b3584268 --- /dev/null +++ b/variadics_macro/src/lib.rs @@ -0,0 +1,47 @@ +#![doc = include_str!("../README.md")] +extern crate proc_macro; + +use proc_macro::TokenStream; +use proc_macro2::Ident; +use quote::{format_ident, quote}; +use syn::parse::{Parse, ParseStream}; +use syn::{parse_macro_input, LitInt}; + +struct InputLen { + input: Ident, + len: LitInt, +} + +impl Parse for InputLen { + fn parse(ts: ParseStream) -> syn::Result { + let input = ts.parse()?; + ts.parse::()?; + let len = ts.parse()?; + Ok(InputLen { input, len }) + } +} + +#[proc_macro] +pub fn tuple(ts: TokenStream) -> TokenStream { + let InputLen { input, len } = parse_macro_input!(ts as InputLen); + let len = len.base10_parse::().unwrap(); + let pattern = (0..len) + .rev() + .map(|i| format_ident!("x{}", i)) + .fold(quote! { () }, |rest, item| quote! { (#item, #rest) }); + let idents = (0..len).map(|i| format_ident!("x{}", i)); + let tuple = quote! { + ( #( #idents, )* ) + }; + + // Create the assignment statement + let expanded = quote! { + { + let #pattern = #input; + let retval = #tuple; + retval + } + }; + + expanded.into() +}