Skip to content
Merged
Show file tree
Hide file tree
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
55 changes: 50 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ pest_derive = "2.8.0"
pretty = "0.12.4"
pretty_assertions = "1.4.1"
zstd = "0.13.2"
relrc = "0.4.1"

# These public dependencies usually require breaking changes downstream, so we
# try to be as permissive as possible.
Expand Down
1 change: 1 addition & 0 deletions hugr-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ thiserror = { workspace = true }
typetag = { workspace = true }
semver = { workspace = true, features = ["serde"] }
zstd = { workspace = true, optional = true }
relrc = { workspace = true, features = ["petgraph"] }

[dev-dependencies]
rstest = { workspace = true }
Expand Down
1 change: 1 addition & 0 deletions hugr-core/src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub mod hugrmut;
pub(crate) mod ident;
pub mod internal;
pub mod patch;
pub mod persistent;
pub mod serialize;
pub mod validate;
pub mod views;
Expand Down
23 changes: 23 additions & 0 deletions hugr-core/src/hugr/patch/simple_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,29 @@ impl<HostNode: HugrNode> SimpleReplacement<HostNode> {
.chain(outgoing_boundary)
.chain(host_to_host_boundary)
}

/// Map the host nodes in `self` according to `node_map`.
///
/// `node_map` must map nodes in the current HUGR of the subgraph to
/// its equivalent nodes in some `new_hugr`.
///
/// This converts a replacement that acts on nodes of type `HostNode` to
/// a replacement that acts on `new_hugr`, with nodes of type `N`.
///
/// This does not check convexity. It is up to the caller to ensure that
/// the mapped replacement obtained from this applies on a convex subgraph
/// of the new HUGR.
pub(crate) fn map_host_nodes<N: HugrNode>(
&self,
node_map: impl Fn(HostNode) -> N,
) -> SimpleReplacement<N> {
let Self {
subgraph,
replacement,
} = self;
let subgraph = subgraph.map_nodes(node_map);
SimpleReplacement::new_unchecked(subgraph, replacement.clone())
}
}

impl<HostNode: HugrNode> PatchVerification for SimpleReplacement<HostNode> {
Expand Down
Loading
Loading