Skip to content

Commit

Permalink
Improve formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Oct 11, 2024
1 parent 8f3578a commit f80655d
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ use std::marker::PhantomData;

use crate::hugr::internal::HugrMutInternals;
use crate::hugr::{HugrView, ValidationError};
use crate::ops;
use crate::ops::{DataflowParent, Input, Output};
use crate::{ops, IncomingPort, OutgoingPort, Wire};
use crate::{Direction, IncomingPort, OutgoingPort, Wire};

use crate::types::{PolyFuncType, Signature, Type};

Expand Down Expand Up @@ -173,19 +174,16 @@ impl FunctionBuilder<Hugr> {
});

// Update the inner input node
let input_types = new_optype.signature.body().input.clone();
let types = new_optype.signature.body().input.clone();
self.hugr_mut()
.replace_op(inp_node, Input { types: input_types })
.unwrap();
let new_port_id = self
.hugr_mut()
.add_ports(inp_node, portgraph::Direction::Outgoing, 1)
.next()
.replace_op(inp_node, Input { types })
.unwrap();
let mut new_port = self.hugr_mut().add_ports(inp_node, Direction::Outgoing, 1);
let new_port = new_port.next().unwrap();

// The last port in an input/output node is an order edge port, so we must shift any connections to it.
let new_value_port: OutgoingPort = (new_port_id - 1).into();
let new_order_port: OutgoingPort = new_port_id.into();
let new_value_port: OutgoingPort = (new_port - 1).into();
let new_order_port: OutgoingPort = new_port.into();
let order_edge_targets = self
.hugr()
.linked_inputs(inp_node, new_value_port)
Expand Down Expand Up @@ -213,24 +211,16 @@ impl FunctionBuilder<Hugr> {
});

// Update the inner input node
let output_types = new_optype.signature.body().output.clone();
let types = new_optype.signature.body().output.clone();
self.hugr_mut()
.replace_op(
out_node,
Output {
types: output_types,
},
)
.unwrap();
let new_port_id = self
.hugr_mut()
.add_ports(out_node, portgraph::Direction::Incoming, 1)
.next()
.replace_op(out_node, Output { types })
.unwrap();
let mut new_port = self.hugr_mut().add_ports(out_node, Direction::Incoming, 1);
let new_port = new_port.next().unwrap();

// The last port in an input/output node is an order edge port, so we must shift any connections to it.
let new_value_port: IncomingPort = (new_port_id - 1).into();
let new_order_port: IncomingPort = new_port_id.into();
let new_value_port: IncomingPort = (new_port - 1).into();
let new_order_port: IncomingPort = new_port.into();
let order_edge_sources = self
.hugr()
.linked_outputs(out_node, new_value_port)
Expand Down

0 comments on commit f80655d

Please sign in to comment.