Skip to main content

hydro_lang/sim/
mod.rs

1//! Deterministic simulation testing support for Hydro programs.
2//!
3//! See [`crate::compile::builder::FlowBuilder::sim`] and [`crate::sim::flow::SimFlow`] for more details.
4
5use std::marker::PhantomData;
6
7use serde::Serialize;
8use serde::de::DeserializeOwned;
9
10use crate::compile::builder::ExternalPortId;
11use crate::live_collections::stream::{Ordering, Retries};
12
13/// A receiver for an external bincode stream in a simulation.
14pub struct SimReceiver<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(
15    pub(crate) ExternalPortId,
16    pub(crate) PhantomData<(T, O, R)>,
17);
18
19/// A sender to an external bincode sink in a simulation.
20pub struct SimSender<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(
21    pub(crate) ExternalPortId,
22    pub(crate) PhantomData<(T, O, R)>,
23);
24
25/// A receiver for an external cluster stream in a simulation.
26///
27/// Each received value is a `(u32, T)` tuple where the `u32` is the raw
28/// cluster member ID that produced the value.
29pub struct SimClusterReceiver<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(
30    pub(crate) ExternalPortId,
31    pub(crate) PhantomData<(T, O, R)>,
32);
33
34/// A sender to an external cluster sink in a simulation.
35///
36/// Each sent value is a `(u32, T)` tuple where the `u32` is the raw
37/// cluster member ID that should receive the value.
38pub struct SimClusterSender<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(
39    pub(crate) ExternalPortId,
40    pub(crate) PhantomData<(T, O, R)>,
41);
42
43/// A sender for an atomic input in a simulation.
44///
45/// The `send` method returns a future that resolves once the atomic tick
46/// containing the sent item has completed processing.
47pub struct SimAtomicSender<T: Serialize + DeserializeOwned, O: Ordering, R: Retries>(
48    pub(crate) SimSender<T, O, R>,
49    pub(crate) SimReceiver<(), O, R>,
50);
51
52#[cfg(stageleft_runtime)]
53mod builder;
54
55#[cfg(stageleft_runtime)]
56pub mod compiled;
57
58#[cfg(stageleft_runtime)]
59pub(crate) mod graph;
60
61#[cfg(stageleft_runtime)]
62pub mod flow;
63
64#[cfg(stageleft_runtime)]
65#[doc(hidden)]
66pub mod runtime;
67
68#[cfg(test)]
69mod tests;