Skip to content

Commit 95da129

Browse files
lmondadacqc-alec
andauthored
feat: Add signature map function for DFGs (#2239)
The boundary map was [recently removed](#2208) in `SimpleReplacement`. Whereas previously, a boundary map could be defined to e.g. permutate the inputs and outputs between the subgraph and the provided replacement, the replacement must now match the subgraph function type as is. This PR adds a `map_function_type` method on DFG HUGRs that can be used to reorder and copy/discard inputs and outputs to the DFG pointed by the entrypoint. For the HUGR to be valid, it is also necessary to update the signatures and links in any enclosing DFGs in the ancestors of the entrypoint. Closes #2211 --------- Co-authored-by: Alec Edgington <54802828+cqc-alec@users.noreply.github.com>
1 parent 9b3fbb4 commit 95da129

7 files changed

+665
-2
lines changed

hugr-core/src/hugr/views.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::collections::HashMap;
1616
pub use self::petgraph::PetgraphWrapper;
1717
use self::render::RenderConfig;
1818
pub use rerooted::Rerooted;
19-
pub use root_checked::{RootCheckable, RootChecked, check_tag};
19+
pub use root_checked::{InvalidSignature, RootCheckable, RootChecked, check_tag};
2020
pub use sibling_subgraph::SiblingSubgraph;
2121

2222
use itertools::Itertools;
@@ -439,7 +439,7 @@ pub trait HugrView: HugrInternals {
439439
.map(|(p, t)| (p.as_incoming().unwrap(), t))
440440
}
441441

442-
/// Iterator over all incoming ports that have Value type, along
442+
/// Iterator over all outgoing ports that have Value type, along
443443
/// with corresponding types.
444444
fn out_value_types(&self, node: Self::Node) -> impl Iterator<Item = (OutgoingPort, Type)> {
445445
self.value_types(node, Direction::Outgoing)

hugr-core/src/hugr/views/root_checked.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ use crate::{Hugr, Node};
77

88
use super::HugrView;
99

10+
mod dfg;
11+
pub use dfg::InvalidSignature;
12+
1013
/// A wrapper over a Hugr that ensures the entrypoint optype is of the required
1114
/// [`OpTag`].
1215
#[derive(Clone)]

0 commit comments

Comments
 (0)