Skip to content

Commit

Permalink
Attempt #3
Browse files Browse the repository at this point in the history
  • Loading branch information
dpetrick committed Dec 31, 2020
1 parent 143593f commit b64c186
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions query-engine/core/src/query_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,30 +575,33 @@ impl QueryGraph {

/// Inserts ordering edges into the graph to prevent interdependency issues when rotating
/// nodes for `if`-flow nodes.
/// All sibling nodes of an if that are _not_ an if node themself or _not_ already connected
/// to the if node in any form (to prevent double edges) will be ordered below the if node
/// in execution predence.
///
/// All sibling nodes of an if-node that are...
/// - ... not an `if`-flow node themself
/// - ... not already connected to the current `if`-flow node in any form (to prevent double edges)
/// - ... not connected to another `if`-flow node with control flow edges (indirect sibling)
/// will be ordered below the currently processed `if`-flow node in execution predence.
///
/// ```text
/// β”Œ ─ ─ ─ ─ ─ ─
/// β”Œ ─ ─ Parent │─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─
/// β”” ─ ─ ─ ─ ─ ─ β”‚ β”‚
/// β”‚ β”‚
/// β”‚ β”‚ β”‚
/// β”‚ β”‚
/// β–Ό β–Ό β–Ό
/// β”‚ β”Œ ─ ─ ─ ─ ─ ─ β”Œ ─ ─ ─ ─ ─ ─ β”Œ ─ ─ ─ ─ ─ ─
/// β”Œ ─ If β”‚ Sibling β”‚ Sibling If β”‚
/// β”‚ β”” ─ ─ ─ ─ ─ ─ β”” ─ ─ ─ ─ ─ ─ β”” ─ ─ ─ ─ ─ ─
/// β”‚ β”‚ β–²
/// β”‚ β”‚ β”‚
/// β”‚ └────Inserted β”€β”€β”€β”€β”˜
/// β”Œ ─ ─ Parent │─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─
/// β”” ─ ─ ─ ─ ─ ─ β”‚ β”‚
/// β”‚ β”‚ β”‚ β”‚
/// β”‚ β”‚ β”‚
/// β”‚ β”‚ β”‚ β”‚
/// β–Ό β–Ό β–Ό β–Ό β”‚
/// β”‚ β”Œ ─ ─ ─ ─ ─ ─ β”Œ ─ ─ ─ ─ ─ ─ β”Œ ─ ─ ─ ─ ─ ─ β”Œ ─ ─ ─ ─ ─ ─
/// β”Œ ─ If β”‚ Sibling β”‚ Sibling If β”‚ Sibling If β”‚ β”‚
/// β”‚ β”” ─ ─ ─ ─ ─ ─ β”” ─ ─ ─ ─ ─ ─ β”” ─ ─ ─ ─ ─ ─ β”” ─ ─ ─ ─ ─ ─
/// β”‚ β”‚ β–² β”‚ β”‚
/// β”‚ β”‚ β”‚
/// β”‚ └────Inserted β”€β”˜ (Then / Else) β”‚
/// β”‚ Ordering
/// β”‚
/// β”‚ β”Œ ─ ─ ─ ─ ─ ─
/// β”‚ Already β”‚
/// β”” ──▢│ connected
/// sibling β”‚
/// β”‚ β–Ό β”‚
/// β”‚ β”Œ ─ ─ ─ ─ ─ ─ β”Œ ─ ─ ─ ─ ─ ─
/// β”‚ Already β”‚ Indirect β”‚ β”‚
/// β”” ──▢│ connected β”‚ sibling ◀─
/// sibling β”‚ ─ ─ ─ ─ ─ ─ β”˜
/// β”” ─ ─ ─ ─ ─ ─
/// ```
fn normalize_if_nodes(&mut self) -> QueryGraphResult<()> {
Expand All @@ -614,9 +617,20 @@ impl QueryGraph {

for (_, sibling) in siblings {
let possible_edge = self.graph.find_edge(node.node_ix, sibling.node_ix);
let is_if_node_child = self
.incoming_edges(&sibling)
.into_iter()
.find(|edge| {
matches!(
self.edge_content(&edge).unwrap(),
QueryGraphDependency::Then | QueryGraphDependency::Else
)
})
.is_some();

if sibling != node
&& possible_edge.is_none()
&& !is_if_node_child
&& !matches!(self.node_content(&sibling).unwrap(), Node::Flow(_))
{
self.create_edge(&node, &sibling, QueryGraphDependency::ExecutionOrder)?;
Expand Down

0 comments on commit b64c186

Please sign in to comment.