diff --git a/docs/src/pages/playground.js b/docs/src/pages/playground.js index b736d417a585..371c71610955 100644 --- a/docs/src/pages/playground.js +++ b/docs/src/pages/playground.js @@ -200,6 +200,7 @@ export function EditorDemo({ compileFn, examples, mermaidId }) { noVarnames: false, noPullPush: false, noHandoffs: false, + noReferences: false, opShortText: false, }); const writeGraphConfigOnChange = (name) => { diff --git a/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_dot.snap b/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_dot.snap index 076eaeaa9e9f..6e13496dcfc8 100644 --- a/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_dot.snap +++ b/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_dot.snap @@ -19,6 +19,7 @@ digraph { n5v1 -> n6v1 n1v1 -> n5v1 n4v1 -> n8v1 [color=darkgreen, style=bold] + n6v1 -> n4v1 [color=red] subgraph "cluster n1v1" { fillcolor="#dddddd" style=filled diff --git a/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_mermaid.snap b/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_mermaid.snap index aa358dd72950..d5b89d5f67f2 100644 --- a/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_mermaid.snap +++ b/hydroflow/tests/snapshots/surface_singleton__state_ref@graphvis_mermaid.snap @@ -22,6 +22,7 @@ linkStyle default stroke:#aaa 5v1-->6v1 1v1-->5v1 4v1==>8v1; linkStyle 5 stroke:#060 +6v1--x4v1; linkStyle 6 stroke:red subgraph sg_1v1 ["sg_1v1 stratum 0"] 1v1 5v1 diff --git a/hydroflow_lang/src/graph/graph_write.rs b/hydroflow_lang/src/graph/graph_write.rs index d33aca4432f6..7d179855239d 100644 --- a/hydroflow_lang/src/graph/graph_write.rs +++ b/hydroflow_lang/src/graph/graph_write.rs @@ -11,7 +11,7 @@ use super::{Color, FlowProps, GraphNodeId, GraphSubgraphId, LatticeFlowType}; /// Trait for writing textual representations of graphs, i.e. mermaid or dot graphs. #[auto_impl(&mut, Box)] -pub trait GraphWrite { +pub(crate) trait GraphWrite { /// Error type emitted by writing. type Err: Error; @@ -34,6 +34,7 @@ pub trait GraphWrite { delay_type: Option, flow_props: Option, label: Option<&str>, + is_reference: bool, ) -> Result<(), Self::Err>; /// Begin writing a subgraph. @@ -164,6 +165,7 @@ where delay_type: Option, flow_props: Option, label: Option<&str>, + _is_reference: bool, ) -> Result<(), Self::Err> { let src_str = format!("{:?}", src_id.data()); let dest_str = format!("{:?}", dst_id.data()); @@ -342,6 +344,7 @@ where delay_type: Option, flow_props: Option, label: Option<&str>, + _is_reference: bool, ) -> Result<(), Self::Err> { let lattice_flow_type = flow_props.and_then(|flow_props| flow_props.lattice_flow_type); let mut properties = Vec::>::new(); diff --git a/hydroflow_lang/src/graph/hydroflow_graph.rs b/hydroflow_lang/src/graph/hydroflow_graph.rs index 9e10f90801dd..05d8c32462e2 100644 --- a/hydroflow_lang/src/graph/hydroflow_graph.rs +++ b/hydroflow_lang/src/graph/hydroflow_graph.rs @@ -19,7 +19,7 @@ use super::{ HANDOFF_NODE_STR, HYDROFLOW, }; use crate::diagnostic::{Diagnostic, Level}; -use crate::graph::ops::null_write_iterator_fn; +use crate::graph::ops::{null_write_iterator_fn, DelayType}; use crate::graph::MODULE_BOUNDARY_NODE_STR; use crate::pretty_span::{PrettyRowCol, PrettySpan}; use crate::process_singletons::postprocess_singletons; @@ -1341,7 +1341,7 @@ impl HydroflowGraph { } /// Write out this `HydroflowGraph` using the given `GraphWrite`. E.g. `Mermaid` or `Dot. - pub fn write_graph( + pub(crate) fn write_graph( &self, mut graph_write: W, write_config: &WriteConfig, @@ -1456,7 +1456,31 @@ impl HydroflowGraph { let delay_type = self .node_op_inst(dst_id) .and_then(|op_inst| (op_inst.op_constraints.input_delaytype_fn)(dst_port)); - graph_write.write_edge(src_id, dst_id, delay_type, flow_props, label.as_deref())?; + graph_write.write_edge( + src_id, + dst_id, + delay_type, + flow_props, + label.as_deref(), + false, + )?; + } + + // Write reference edges. + if !write_config.no_references { + for src_id in self.node_ids() { + for dst_id in self + .node_singleton_references(src_id) + .iter() + .copied() + .flatten() + { + let delay_type = Some(DelayType::Stratum); + let flow_props = None; + let label = None; + graph_write.write_edge(src_id, dst_id, delay_type, flow_props, label, true)?; + } + } } // Write subgraphs. @@ -1588,6 +1612,9 @@ pub struct WriteConfig { /// Will not render handoffs if set. #[cfg_attr(feature = "debugging", arg(long))] pub no_handoffs: bool, + /// Will not render singleton references if set. + #[cfg_attr(feature = "debugging", arg(long))] + pub no_references: bool, /// Op text will only be their name instead of the whole source. #[cfg_attr(feature = "debugging", arg(long))] diff --git a/website_playground/src/lib.rs b/website_playground/src/lib.rs index e45c059802ba..4edbe93c8d0d 100644 --- a/website_playground/src/lib.rs +++ b/website_playground/src/lib.rs @@ -111,6 +111,7 @@ pub fn compile_hydroflow( no_varnames: bool, no_pull_push: bool, no_handoffs: bool, + no_references: bool, op_short_text: bool, ) -> JsValue { let write_config = WriteConfig { @@ -118,6 +119,7 @@ pub fn compile_hydroflow( no_varnames, no_pull_push, no_handoffs, + no_references, op_short_text, }; @@ -164,6 +166,7 @@ pub fn compile_datalog( no_varnames: bool, no_pull_push: bool, no_handoffs: bool, + no_references: bool, op_short_text: bool, ) -> JsValue { let write_config = WriteConfig { @@ -171,6 +174,7 @@ pub fn compile_datalog( no_varnames, no_pull_push, no_handoffs, + no_references, op_short_text, };