Skip to content

Commit

Permalink
Add SiblingSubgraph view (#336)
Browse files Browse the repository at this point in the history
Co-authored-by: Seyon Sivarajah <[email protected]>
Co-authored-by: Agustín Borgna <[email protected]>
Co-authored-by: Alan Lawrence <[email protected]>
  • Loading branch information
4 people authored Aug 22, 2023
1 parent 377dc57 commit caacecf
Show file tree
Hide file tree
Showing 4 changed files with 583 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/hugr/rewrite/simple_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crate::{
use thiserror::Error;

/// Specification of a simple replacement operation.
// TODO: use `SiblingSubgraph` to define the replacement.
#[derive(Debug, Clone)]
pub struct SimpleReplacement {
/// The common DataflowParent of all nodes to be replaced.
Expand Down
4 changes: 3 additions & 1 deletion src/hugr/views.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
//! Read-only access into HUGR graphs and subgraphs.
pub mod hierarchy;
pub mod sibling;

pub use hierarchy::{DescendantsGraph, HierarchyView, SiblingGraph};
pub use sibling::SiblingSubgraph;

use context_iterators::{ContextIterator, IntoContextIterator, MapWithCtx};
use itertools::{Itertools, MapInto};
use portgraph::dot::{DotFormat, EdgeStyle, NodeStyle, PortStyle};
use portgraph::{multiportgraph, LinkView, MultiPortGraph, PortView};

use super::{Hugr, NodeMetadata, NodeType};
use super::{Node, Port};
use crate::ops::handle::NodeHandle;
use crate::ops::{OpName, OpTag, OpType};
use crate::types::EdgeKind;
use crate::Direction;
use crate::{Node, Port};

/// A trait for inspecting HUGRs.
/// For end users we intend this to be superseded by region-specific APIs.
Expand Down
8 changes: 4 additions & 4 deletions src/hugr/views/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ where
impl<'g, Root, Base> Clone for SiblingGraph<'g, Root, Base>
where
Root: NodeHandle,
Base: HugrInternals + HugrView + Clone,
Base: HugrInternals + HugrView,
{
fn clone(&self) -> Self {
SiblingGraph::new(self.hugr, self.root)
Expand Down Expand Up @@ -384,7 +384,7 @@ where
impl<'a, Root, Base> HierarchyView<'a> for SiblingGraph<'a, Root, Base>
where
Root: NodeHandle,
Base: HugrInternals + HugrView,
Base: HugrView,
{
type Base = Base;

Expand All @@ -410,7 +410,7 @@ where
impl<'a, Root, Base> HierarchyView<'a> for DescendantsGraph<'a, Root, Base>
where
Root: NodeHandle,
Base: HugrInternals + HugrView,
Base: HugrView,
{
type Base = Base;

Expand All @@ -433,7 +433,7 @@ where
}
}

impl<'g, Root, Base> super::sealed::HugrInternals for SiblingGraph<'g, Root, Base>
impl<'g, Root, Base> HugrInternals for SiblingGraph<'g, Root, Base>
where
Root: NodeHandle,
Base: HugrInternals,
Expand Down
Loading

0 comments on commit caacecf

Please sign in to comment.