Skip to content

Commit

Permalink
Update required port connection test
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Jun 23, 2023
1 parent 70332c4 commit c4f20e3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ impl<'a> ValidationContext<'a> {
let port_kind = optype.port_kind(port).unwrap();
let dir = port.direction();

// Input ports and output linear ports must always be connected
let mut links = self.hugr.graph.port_links(port_index).peekable();
let must_be_connected = match dir {
// Incoming ports must be connected, except for state order ports, branch case nodes,
// and the input of some BasicBlocks.
Direction::Incoming => {
port_kind.is_linear() || matches!(port_kind, EdgeKind::Static(_))
port_kind != EdgeKind::StateOrder
&& port_kind != EdgeKind::ControlFlow
&& optype.tag() != OpTag::Case
}
Direction::Outgoing => port_kind.is_linear(),
// Linear values and cfg edges must be connected.
Direction::Outgoing => port_kind.is_linear() || optype.tag() == OpTag::BasicBlock,
};
if must_be_connected && links.peek().is_none() {
return Err(ValidationError::UnconnectedPort {
Expand Down

0 comments on commit c4f20e3

Please sign in to comment.