pub struct DfirGraph { /* private fields */ }
Expand description
An abstract “meta graph” representation of a Hydroflow graph.
Can be with or without subgraph partitioning, stratification, and handoff insertion. This is the meta graph used for generating Rust source code in macros from Hydroflow surface sytnax.
This struct has a lot of methods for manipulating the graph, vaguely grouped together in
separate impl
blocks. You might notice a few particularly specific arbitray-seeming methods
in here–those are just what was needed for the compilation algorithms. If you need another
method then add it.
Implementations§
source§impl DfirGraph
impl DfirGraph
Node methods.
sourcepub fn node(&self, node_id: GraphNodeId) -> &GraphNode
pub fn node(&self, node_id: GraphNodeId) -> &GraphNode
Get a node with its operator instance (if applicable).
sourcepub fn node_op_inst(&self, node_id: GraphNodeId) -> Option<&OperatorInstance>
pub fn node_op_inst(&self, node_id: GraphNodeId) -> Option<&OperatorInstance>
Get the OperatorInstance
for a given node. Node must be an operator and have an
OperatorInstance
present, otherwise will return None
.
Note that no operator instances will be persent after deserialization.
sourcepub fn node_varname(&self, node_id: GraphNodeId) -> Option<Ident>
pub fn node_varname(&self, node_id: GraphNodeId) -> Option<Ident>
Get the debug variable name attached to a graph node.
sourcepub fn node_subgraph(&self, node_id: GraphNodeId) -> Option<GraphSubgraphId>
pub fn node_subgraph(&self, node_id: GraphNodeId) -> Option<GraphSubgraphId>
Get subgraph for node.
sourcepub fn node_degree_in(&self, node_id: GraphNodeId) -> usize
pub fn node_degree_in(&self, node_id: GraphNodeId) -> usize
Degree into a node, i.e. the number of predecessors.
sourcepub fn node_degree_out(&self, node_id: GraphNodeId) -> usize
pub fn node_degree_out(&self, node_id: GraphNodeId) -> usize
Degree out of a node, i.e. the number of successors.
sourcepub fn node_successors(
&self,
src: GraphNodeId,
) -> impl '_ + DoubleEndedIterator<Item = (GraphEdgeId, GraphNodeId)> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn node_successors( &self, src: GraphNodeId, ) -> impl '_ + DoubleEndedIterator<Item = (GraphEdgeId, GraphNodeId)> + ExactSizeIterator + FusedIterator + Clone + Debug
Successors, iterator of (GraphEdgeId, GraphNodeId)
of outgoing edges.
sourcepub fn node_predecessors(
&self,
dst: GraphNodeId,
) -> impl '_ + DoubleEndedIterator<Item = (GraphEdgeId, GraphNodeId)> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn node_predecessors( &self, dst: GraphNodeId, ) -> impl '_ + DoubleEndedIterator<Item = (GraphEdgeId, GraphNodeId)> + ExactSizeIterator + FusedIterator + Clone + Debug
Predecessors, iterator of (GraphEdgeId, GraphNodeId)
of incoming edges.
sourcepub fn node_successor_edges(
&self,
src: GraphNodeId,
) -> impl '_ + DoubleEndedIterator<Item = GraphEdgeId> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn node_successor_edges( &self, src: GraphNodeId, ) -> impl '_ + DoubleEndedIterator<Item = GraphEdgeId> + ExactSizeIterator + FusedIterator + Clone + Debug
Successor edges, iterator of GraphEdgeId
of outgoing edges.
sourcepub fn node_predecessor_edges(
&self,
dst: GraphNodeId,
) -> impl '_ + DoubleEndedIterator<Item = GraphEdgeId> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn node_predecessor_edges( &self, dst: GraphNodeId, ) -> impl '_ + DoubleEndedIterator<Item = GraphEdgeId> + ExactSizeIterator + FusedIterator + Clone + Debug
Predecessor edges, iterator of GraphEdgeId
of incoming edges.
sourcepub fn node_successor_nodes(
&self,
src: GraphNodeId,
) -> impl '_ + DoubleEndedIterator<Item = GraphNodeId> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn node_successor_nodes( &self, src: GraphNodeId, ) -> impl '_ + DoubleEndedIterator<Item = GraphNodeId> + ExactSizeIterator + FusedIterator + Clone + Debug
Successor nodes, iterator of GraphNodeId
.
sourcepub fn node_predecessor_nodes(
&self,
dst: GraphNodeId,
) -> impl '_ + DoubleEndedIterator<Item = GraphNodeId> + ExactSizeIterator + FusedIterator + Clone + Debug
pub fn node_predecessor_nodes( &self, dst: GraphNodeId, ) -> impl '_ + DoubleEndedIterator<Item = GraphNodeId> + ExactSizeIterator + FusedIterator + Clone + Debug
Predecessor nodes, iterator of GraphNodeId
.
sourcepub fn node_ids(&self) -> Keys<'_, GraphNodeId, GraphNode>
pub fn node_ids(&self) -> Keys<'_, GraphNodeId, GraphNode>
Iterator of node IDs GraphNodeId
.
sourcepub fn nodes(&self) -> Iter<'_, GraphNodeId, GraphNode>
pub fn nodes(&self) -> Iter<'_, GraphNodeId, GraphNode>
Iterator over (GraphNodeId, &Node)
pairs.
sourcepub fn insert_node(
&mut self,
node: GraphNode,
varname_opt: Option<Ident>,
loop_opt: Option<GraphLoopId>,
) -> GraphNodeId
pub fn insert_node( &mut self, node: GraphNode, varname_opt: Option<Ident>, loop_opt: Option<GraphLoopId>, ) -> GraphNodeId
Insert a node, assigning the given varname.
sourcepub fn insert_node_op_inst(
&mut self,
node_id: GraphNodeId,
op_inst: OperatorInstance,
)
pub fn insert_node_op_inst( &mut self, node_id: GraphNodeId, op_inst: OperatorInstance, )
Insert an operator instance for the given node. Panics if already set.
sourcepub fn insert_node_op_insts_all(&mut self, diagnostics: &mut Vec<Diagnostic>)
pub fn insert_node_op_insts_all(&mut self, diagnostics: &mut Vec<Diagnostic>)
Assign all operator instances if not set. Write diagnostic messages/errors into diagnostics
.
sourcepub fn insert_intermediate_node(
&mut self,
edge_id: GraphEdgeId,
new_node: GraphNode,
) -> (GraphNodeId, GraphEdgeId)
pub fn insert_intermediate_node( &mut self, edge_id: GraphEdgeId, new_node: GraphNode, ) -> (GraphNodeId, GraphEdgeId)
Inserts a node between two existing nodes connected by the given edge_id
.
edge
: (src, dst, dst_idx)
Before: A (src) ————> B (dst) After: A (src) -> X (new) -> B (dst)
Returns the ID of X & ID of edge OUT of X.
Note that both the edges will be new and edge_id
will be removed. Both new edges will
get the edge type of the original edge.
sourcepub fn remove_intermediate_node(&mut self, node_id: GraphNodeId)
pub fn remove_intermediate_node(&mut self, node_id: GraphNodeId)
Remove the node node_id
but preserves and connects the single predecessor and single successor.
Panics if the node does not have exactly one predecessor and one successor, or is not in the graph.
source§impl DfirGraph
impl DfirGraph
Singleton references.
sourcepub fn set_node_singleton_references(
&mut self,
node_id: GraphNodeId,
singletons_referenced: Vec<Option<GraphNodeId>>,
) -> Option<Vec<Option<GraphNodeId>>>
pub fn set_node_singleton_references( &mut self, node_id: GraphNodeId, singletons_referenced: Vec<Option<GraphNodeId>>, ) -> Option<Vec<Option<GraphNodeId>>>
Set the singletons referenced for the node_id
operator. Each reference corresponds to the
same index in the crate::parse::Operator::singletons_referenced
vec.
sourcepub fn node_singleton_references(
&self,
node_id: GraphNodeId,
) -> &[Option<GraphNodeId>]
pub fn node_singleton_references( &self, node_id: GraphNodeId, ) -> &[Option<GraphNodeId>]
Gets the singletons referenced by a node. Returns an empty iterator for non-operators and operators that do not reference singletons.
source§impl DfirGraph
impl DfirGraph
Module methods.
sourcepub fn merge_modules(&mut self) -> Result<(), Diagnostic>
pub fn merge_modules(&mut self) -> Result<(), Diagnostic>
When modules are imported into a flat graph, they come with an input and output ModuleBoundary node. The partitioner doesn’t understand these nodes and will panic if it encounters them. merge_modules removes them from the graph, stitching the input and ouput sides of the ModuleBondaries based on their ports For example: source_iter([]) -> [myport]ModuleBoundary(input)[my_port] -> map(|x| x) -> ModuleBoundary(output) -> null(); in the above eaxmple, the [myport] port will be used to connect the source_iter with the map that is inside of the module. The output module boundary has elided ports, this is also used to match up the input/output across the module boundary.
source§impl DfirGraph
impl DfirGraph
Edge methods.
sourcepub fn edge(&self, edge_id: GraphEdgeId) -> (GraphNodeId, GraphNodeId)
pub fn edge(&self, edge_id: GraphEdgeId) -> (GraphNodeId, GraphNodeId)
Get the src
and dst
for an edge: (src GraphNodeId, dst GraphNodeId)
.
sourcepub fn edge_ports(
&self,
edge_id: GraphEdgeId,
) -> (&PortIndexValue, &PortIndexValue)
pub fn edge_ports( &self, edge_id: GraphEdgeId, ) -> (&PortIndexValue, &PortIndexValue)
Get the source and destination ports for an edge: (src &PortIndexValue, dst &PortIndexValue)
.
sourcepub fn edge_ids(&self) -> Keys<'_, GraphEdgeId, (GraphNodeId, GraphNodeId)>
pub fn edge_ids(&self) -> Keys<'_, GraphEdgeId, (GraphNodeId, GraphNodeId)>
Iterator of all edge IDs GraphEdgeId
.
sourcepub fn edges(
&self,
) -> impl '_ + ExactSizeIterator<Item = (GraphEdgeId, (GraphNodeId, GraphNodeId))> + FusedIterator + Clone + Debug
pub fn edges( &self, ) -> impl '_ + ExactSizeIterator<Item = (GraphEdgeId, (GraphNodeId, GraphNodeId))> + FusedIterator + Clone + Debug
Iterator over all edges: (GraphEdgeId, (src GraphNodeId, dst GraphNodeId))
.
sourcepub fn insert_edge(
&mut self,
src: GraphNodeId,
src_port: PortIndexValue,
dst: GraphNodeId,
dst_port: PortIndexValue,
) -> GraphEdgeId
pub fn insert_edge( &mut self, src: GraphNodeId, src_port: PortIndexValue, dst: GraphNodeId, dst_port: PortIndexValue, ) -> GraphEdgeId
Insert an edge between nodes thru the given ports.
sourcepub fn remove_edge(&mut self, edge: GraphEdgeId)
pub fn remove_edge(&mut self, edge: GraphEdgeId)
Removes an edge and its corresponding ports and edge type info.
source§impl DfirGraph
impl DfirGraph
Subgraph methods.
sourcepub fn subgraph(&self, subgraph_id: GraphSubgraphId) -> &Vec<GraphNodeId>
pub fn subgraph(&self, subgraph_id: GraphSubgraphId) -> &Vec<GraphNodeId>
Nodes belonging to the given subgraph.
sourcepub fn subgraph_ids(&self) -> Keys<'_, GraphSubgraphId, Vec<GraphNodeId>>
pub fn subgraph_ids(&self) -> Keys<'_, GraphSubgraphId, Vec<GraphNodeId>>
Iterator over all subgraph IDs.
sourcepub fn subgraphs(&self) -> Iter<'_, GraphSubgraphId, Vec<GraphNodeId>>
pub fn subgraphs(&self) -> Iter<'_, GraphSubgraphId, Vec<GraphNodeId>>
Iterator over all subgraphs, ID and members: (GraphSubgraphId, Vec<GraphNodeId>)
.
sourcepub fn insert_subgraph(
&mut self,
node_ids: Vec<GraphNodeId>,
) -> Result<GraphSubgraphId, (GraphNodeId, GraphSubgraphId)>
pub fn insert_subgraph( &mut self, node_ids: Vec<GraphNodeId>, ) -> Result<GraphSubgraphId, (GraphNodeId, GraphSubgraphId)>
Create a subgraph consisting of node_ids
. Returns an error if any of the nodes are already in a subgraph.
sourcepub fn remove_from_subgraph(&mut self, node_id: GraphNodeId) -> bool
pub fn remove_from_subgraph(&mut self, node_id: GraphNodeId) -> bool
Removes a node from its subgraph. Returns true if the node was in a subgraph.
sourcepub fn subgraph_stratum(&self, sg_id: GraphSubgraphId) -> Option<usize>
pub fn subgraph_stratum(&self, sg_id: GraphSubgraphId) -> Option<usize>
Gets the stratum number of the subgraph.
sourcepub fn set_subgraph_stratum(
&mut self,
sg_id: GraphSubgraphId,
stratum: usize,
) -> Option<usize>
pub fn set_subgraph_stratum( &mut self, sg_id: GraphSubgraphId, stratum: usize, ) -> Option<usize>
Set subgraph’s stratum number, returning the old value if exists.
sourcepub fn set_subgraph_laziness(
&mut self,
sg_id: GraphSubgraphId,
lazy: bool,
) -> bool
pub fn set_subgraph_laziness( &mut self, sg_id: GraphSubgraphId, lazy: bool, ) -> bool
Set subgraph’s laziness, returning the old value.
sourcepub fn max_stratum(&self) -> Option<usize>
pub fn max_stratum(&self) -> Option<usize>
Returns the the stratum number of the largest (latest) stratum (inclusive).
source§impl DfirGraph
impl DfirGraph
Display/output methods.
sourcepub fn as_code(
&self,
root: &TokenStream,
include_type_guards: bool,
prefix: TokenStream,
diagnostics: &mut Vec<Diagnostic>,
) -> TokenStream
pub fn as_code( &self, root: &TokenStream, include_type_guards: bool, prefix: TokenStream, diagnostics: &mut Vec<Diagnostic>, ) -> TokenStream
Emit this HydroflowGraph
as runnable Rust source code tokens.
sourcepub fn node_color_map(&self) -> SparseSecondaryMap<GraphNodeId, Color>
pub fn node_color_map(&self) -> SparseSecondaryMap<GraphNodeId, Color>
Color mode (pull vs. push, handoff vs. comp) for nodes. Some nodes can be push OR pull; those nodes will not be set in the returned map.
sourcepub fn to_mermaid(&self, write_config: &WriteConfig) -> String
pub fn to_mermaid(&self, write_config: &WriteConfig) -> String
Writes this graph as mermaid into a string.
sourcepub fn write_mermaid(
&self,
output: impl Write,
write_config: &WriteConfig,
) -> Result
pub fn write_mermaid( &self, output: impl Write, write_config: &WriteConfig, ) -> Result
Writes this graph as mermaid into the given Write
.
sourcepub fn to_dot(&self, write_config: &WriteConfig) -> String
pub fn to_dot(&self, write_config: &WriteConfig) -> String
Writes this graph as DOT (graphviz) into a string.
sourcepub fn write_dot(
&self,
output: impl Write,
write_config: &WriteConfig,
) -> Result
pub fn write_dot( &self, output: impl Write, write_config: &WriteConfig, ) -> Result
Writes this graph as DOT (graphviz) into the given Write
.
sourcepub fn surface_syntax_string(&self) -> String
pub fn surface_syntax_string(&self) -> String
Convert back into surface syntax.
sourcepub fn write_surface_syntax(&self, write: &mut impl Write) -> Result
pub fn write_surface_syntax(&self, write: &mut impl Write) -> Result
Convert back into surface syntax.
sourcepub fn mermaid_string_flat(&self) -> String
pub fn mermaid_string_flat(&self) -> String
Convert into a mermaid graph. Ignores subgraphs.
sourcepub fn write_mermaid_flat(&self, write: &mut impl Write) -> Result
pub fn write_mermaid_flat(&self, write: &mut impl Write) -> Result
Convert into a mermaid graph. Ignores subgraphs.
source§impl DfirGraph
impl DfirGraph
Loops
sourcepub fn loop_ids(&self) -> Keys<'_, GraphLoopId, Vec<GraphNodeId>>
pub fn loop_ids(&self) -> Keys<'_, GraphLoopId, Vec<GraphNodeId>>
Iterator over all loop IDs.
sourcepub fn loops(&self) -> Iter<'_, GraphLoopId, Vec<GraphNodeId>>
pub fn loops(&self) -> Iter<'_, GraphLoopId, Vec<GraphNodeId>>
Iterator over all loops, ID and members: (GraphLoopId, Vec<GraphNodeId>)
.
sourcepub fn insert_loop(&mut self, parent_loop: Option<GraphLoopId>) -> GraphLoopId
pub fn insert_loop(&mut self, parent_loop: Option<GraphLoopId>) -> GraphLoopId
Create a new loop context, with the given parent loop (or None
).
sourcepub fn node_loop(&self, node_id: GraphNodeId) -> Option<GraphLoopId>
pub fn node_loop(&self, node_id: GraphNodeId) -> Option<GraphLoopId>
Get a node’s loop context (or None
for root).
sourcepub fn loop_parent(&self, loop_id: GraphLoopId) -> Option<GraphLoopId>
pub fn loop_parent(&self, loop_id: GraphLoopId) -> Option<GraphLoopId>
Get a loop context’s parent loop context (or None
for root).
sourcepub fn loop_children(&self, loop_id: GraphLoopId) -> &Vec<GraphLoopId>
pub fn loop_children(&self, loop_id: GraphLoopId) -> &Vec<GraphLoopId>
Get a loop context’s child loops.
source§impl DfirGraph
impl DfirGraph
sourcepub fn open_mermaid(&self, write_config: &WriteConfig) -> Result<()>
pub fn open_mermaid(&self, write_config: &WriteConfig) -> Result<()>
Opens this as a mermaid graph in the mermaid.live browser editor.
sourcepub fn open_dot(&self, write_config: &WriteConfig) -> Result<()>
pub fn open_dot(&self, write_config: &WriteConfig) -> Result<()>
Opens this as dot/graphviz graph in the Graphviz Online browser editor.
sourcepub fn open_graph(
&self,
graph_type: WriteGraphType,
write_config: Option<WriteConfig>,
) -> Result<()>
pub fn open_graph( &self, graph_type: WriteGraphType, write_config: Option<WriteConfig>, ) -> Result<()>
Opens the graph based on graph_type
, which can be parsed by clap.
Trait Implementations§
source§impl<'de> Deserialize<'de> for DfirGraph
impl<'de> Deserialize<'de> for DfirGraph
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for DfirGraph
impl !RefUnwindSafe for DfirGraph
impl !Send for DfirGraph
impl !Sync for DfirGraph
impl Unpin for DfirGraph
impl !UnwindSafe for DfirGraph
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more