Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Serialize index of control-flow ports #1924

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions hugr-core/src/hugr/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use thiserror::Error;
use crate::core::NodeIndex;
use crate::hugr::Hugr;
use crate::ops::OpType;
use crate::{Node, PortIndex};
use crate::types::EdgeKind;
use crate::{Node, Port, PortIndex};
use portgraph::hierarchy::AttachError;
use portgraph::{Direction, LinkError, PortView};

Expand Down Expand Up @@ -180,10 +181,14 @@ impl TryFrom<&Hugr> for SerHugrLatest {
.expect("Could not reach one of the nodes");

let find_offset = |node: Node, offset: usize, dir: Direction, hugr: &Hugr| {
let op = hugr.get_optype(node);
let is_value_port = offset < op.value_port_count(dir);
let is_static_input = op.static_port(dir).is_some_and(|p| p.index() == offset);
let offset = (is_value_port || is_static_input).then_some(offset as u16);
let offset = matches!(
hugr.get_optype(node).port_kind(Port::new(dir, offset)),
Some(EdgeKind::ControlFlow)
| Some(EdgeKind::Function(_))
| Some(EdgeKind::Const(_))
| Some(EdgeKind::Value(_))
)
.then_some(offset as u16);
(node_rekey[&node], offset)
};

Expand Down
Loading