dfir_lang/graph/ops/
state.rs

1use syn::parse_quote_spanned;
2use super::{
3    OperatorCategory, OperatorConstraints,
4    WriteContextArgs, RANGE_1,
5};
6
7// TODO(mingwei): Improve example when things are more stable.
8/// A lattice-based state operator, used for accumulating lattice state
9///
10/// Emits both a referenceable singleton and (optionally) a pass-through stream. In the future the
11/// pass-through stream may be deduplicated.
12///
13/// ```dfir
14/// use std::collections::HashSet;
15///
16/// use lattices::set_union::{CartesianProductBimorphism, SetUnionHashSet, SetUnionSingletonSet};
17///
18/// my_state = source_iter(0..3)
19///     -> map(SetUnionSingletonSet::new_from)
20///     -> state::<SetUnionHashSet<usize>>();
21/// ```
22/// The `state` operator is equivalent to `state_by` used with an identity mapping operator with
23/// `Default::default` providing the factory function.
24pub const STATE: OperatorConstraints = OperatorConstraints {
25    name: "state",
26    categories: &[OperatorCategory::Persistence],
27    hard_range_inn: RANGE_1,
28    soft_range_inn: RANGE_1,
29    hard_range_out: &(0..=1),
30    soft_range_out: &(0..=1),
31    num_args: 0,
32    persistence_args: &(0..=1),
33    type_args: &(0..=1),
34    is_external_input: false,
35    has_singleton_output: true,
36    flo_type: None,
37    ports_inn: None,
38    ports_out: None,
39    input_delaytype_fn: |_| None,
40    write_fn: |wc @ &WriteContextArgs { op_span, .. },
41               diagnostics| {
42
43        let wc = WriteContextArgs {
44            arguments: &parse_quote_spanned!(op_span => ::std::convert::identity, ::std::default::Default::default),
45            ..wc.clone()
46        };
47
48        (super::state_by::STATE_BY.write_fn)(&wc, diagnostics)
49    },
50};