Skip to content

Commit

Permalink
fix(hydroflow_lang): restore in-subgraph rendering of self-handoffs (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MingweiSamuel committed Oct 10, 2023
1 parent e519fb1 commit 2edf779
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ digraph {
fillcolor="#dddddd"
style=filled
label = "sg_1v1\nstratum 0"
n13v1
n1v1
n2v1
n4v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ linkStyle default stroke:#aaa
13v1-->9v1
14v1-->|1|10v1
subgraph sg_1v1 ["sg_1v1 stratum 0"]
13v1
1v1
2v1
4v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ digraph {
fillcolor="#dddddd"
style=filled
label = "sg_1v1\nstratum 0"
n9v1
n3v1
n1v1
n2v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linkStyle default stroke:#aaa
6v1-->|1|8v1
9v1-->|1|1v1
subgraph sg_1v1 ["sg_1v1 stratum 0"]
9v1
3v1
1v1
2v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ digraph {
fillcolor="#dddddd"
style=filled
label = "sg_2v1\nstratum 0"
n10v1
n6v1
n5v1
n7v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ subgraph sg_1v1 ["sg_1v1 stratum 0"]
end
end
subgraph sg_2v1 ["sg_2v1 stratum 0"]
10v1
6v1
5v1
7v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ linkStyle default stroke:#aaa
6v1-->|print|8v1
10v1-->|cycle|7v1
subgraph sg_1v1 ["sg_1v1 stratum 0"]
10v1
1v1
2v1
7v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ linkStyle default stroke:#aaa
17v1-->|pos|11v1
18v1--x|neg|11v1; linkStyle 18 stroke:red
subgraph sg_1v1 ["sg_1v1 stratum 0"]
15v1
1v1
4v1
5v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ digraph {
fillcolor="#dddddd"
style=filled
label = "sg_1v1\nstratum 0"
n10v1
n3v1
n1v1
n2v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ linkStyle default stroke:#aaa
10v1-->|1|1v1
11v1--x8v1; linkStyle 10 stroke:red
subgraph sg_1v1 ["sg_1v1 stratum 0"]
10v1
3v1
1v1
2v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ digraph {
fillcolor="#dddddd"
style=filled
label = "sg_2v1\nstratum 0"
n15v1
n3v1
n1v1
n2v1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ subgraph sg_1v1 ["sg_1v1 stratum 0"]
end
end
subgraph sg_2v1 ["sg_2v1 stratum 0"]
15v1
3v1
1v1
2v1
Expand Down
29 changes: 21 additions & 8 deletions hydroflow_lang/src/graph/hydroflow_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,10 +1175,23 @@ impl HydroflowGraph {

// Write nodes.
let mut skipped_handoffs = BTreeSet::new();
let mut subgraph_handoffs = <BTreeMap<GraphSubgraphId, Vec<GraphNodeId>>>::new();
for (node_id, node) in self.nodes() {
if write_config.no_handoffs && matches!(node, Node::Handoff { .. }) {
skipped_handoffs.insert(node_id);
continue;
if matches!(node, Node::Handoff { .. }) {
if write_config.no_handoffs {
skipped_handoffs.insert(node_id);
continue;
} else {
let pred_node = self.node_predecessor_nodes(node_id).next().unwrap();
let pred_sg = self.node_subgraph(pred_node);
let succ_node = self.node_successor_nodes(node_id).next().unwrap();
let succ_sg = self.node_subgraph(succ_node);
if let Some((pred_sg, succ_sg)) = pred_sg.zip(succ_sg) {
if pred_sg == succ_sg {
subgraph_handoffs.entry(pred_sg).or_default().push(node_id);
}
}
}
}
graph_write.write_node(
node_id,
Expand Down Expand Up @@ -1221,12 +1234,12 @@ impl HydroflowGraph {
// Write subgraphs.
if !write_config.no_subgraphs {
for (subgraph_id, subgraph_node_ids) in self.subgraph_nodes.iter() {
let handoff_node_ids = subgraph_handoffs.get(&subgraph_id).into_iter().flatten();
let subgraph_node_ids = subgraph_node_ids.iter();
let all_node_ids = handoff_node_ids.chain(subgraph_node_ids).copied();

let stratum = self.subgraph_stratum.get(subgraph_id);
graph_write.write_subgraph_start(
subgraph_id,
*stratum.unwrap(),
subgraph_node_ids.iter().copied(),
)?;
graph_write.write_subgraph_start(subgraph_id, *stratum.unwrap(), all_node_ids)?;
// Write out any variable names within the subgraph.
if !write_config.no_varnames {
for (varname, varname_node_ids) in
Expand Down

0 comments on commit 2edf779

Please sign in to comment.