Skip to content

Commit

Permalink
Reorganise HUGR views (#386)
Browse files Browse the repository at this point in the history
I have moved the file reorganisation out of #336. Please ignore the
slightly
messy history, this will get squashed away.

---------

Co-authored-by: Seyon Sivarajah <[email protected]>
  • Loading branch information
lmondada and ss2165 authored Aug 9, 2023
1 parent dc97710 commit 383765d
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/algorithm/half_node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::hash::Hash;

use super::nest_cfgs::CfgView;
use crate::hugr::view::HugrView;
use crate::hugr::views::HugrView;
use crate::ops::OpTag;
use crate::ops::OpTrait;
use crate::{Direction, Node};
Expand Down
4 changes: 2 additions & 2 deletions src/algorithm/nest_cfgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use std::hash::Hash;

use itertools::Itertools;

use crate::hugr::view::HugrView;
use crate::hugr::views::HugrView;
use crate::ops::OpTag;
use crate::ops::OpTrait;
use crate::{Direction, Node};
Expand Down Expand Up @@ -398,7 +398,7 @@ impl<T: Copy + Clone + PartialEq + Eq + Hash> EdgeClassifier<T> {
pub(crate) mod test {
use super::*;
use crate::builder::{BuildError, CFGBuilder, Container, DataflowSubContainer, HugrBuilder};
use crate::hugr::hierarchical_views::{HierarchyView, SiblingGraph};
use crate::hugr::views::{HierarchyView, SiblingGraph};
use crate::ops::handle::{BasicBlockID, ConstID, NodeHandle};
use crate::ops::Const;
use crate::types::{ClassicType, SimpleType};
Expand Down
2 changes: 1 addition & 1 deletion src/builder/build_traits.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::hugr::validate::InterGraphEdgeError;
use crate::hugr::view::HugrView;
use crate::hugr::views::HugrView;
use crate::hugr::{Node, NodeMetadata, Port, ValidationError};
use crate::ops::{self, LeafOp, OpTrait, OpType};

Expand Down
2 changes: 1 addition & 1 deletion src/builder/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
BasicBlockID, BuildError, CfgID, Container, Dataflow, HugrBuilder, Wire,
};

use crate::hugr::view::HugrView;
use crate::hugr::views::HugrView;
use crate::ops::handle::NodeHandle;
use crate::ops::{self, BasicBlock, OpType};
use crate::types::AbstractSignature;
Expand Down
2 changes: 1 addition & 1 deletion src/builder/conditional.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::hugr::view::HugrView;
use crate::hugr::views::HugrView;
use crate::types::{AbstractSignature, ClassicRow, SimpleRow};

use crate::ops;
Expand Down
2 changes: 1 addition & 1 deletion src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use super::{
};

use crate::{
hugr::{view::HugrView, ValidationError},
hugr::{views::HugrView, ValidationError},
ops,
types::{simple::TypeTag, PrimType, SimpleType},
};
Expand Down
2 changes: 1 addition & 1 deletion src/builder/tail_loop.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::ops::{self, OpType};

use crate::hugr::{view::HugrView, NodeType};
use crate::hugr::{views::HugrView, NodeType};
use crate::types::{AbstractSignature, ClassicRow, SimpleRow};
use crate::{Hugr, Node};

Expand Down
5 changes: 2 additions & 3 deletions src/hugr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@

mod hugrmut;

pub mod hierarchical_views;
pub mod rewrite;
pub mod serialize;
pub mod validate;
pub mod view;
pub mod views;

use std::collections::VecDeque;
use std::iter;
Expand All @@ -24,7 +23,7 @@ use thiserror::Error;
#[cfg(feature = "pyo3")]
use pyo3::prelude::*;

pub use self::view::HugrView;
pub use self::views::HugrView;
use crate::ops::{OpTag, OpTrait, OpType};
use crate::resource::ResourceSet;
use crate::types::{AbstractSignature, Signature};
Expand Down
2 changes: 1 addition & 1 deletion src/hugr/rewrite/simple_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ mod test {
BuildError, Container, DFGBuilder, Dataflow, DataflowHugr, DataflowSubContainer,
HugrBuilder, ModuleBuilder,
};
use crate::hugr::view::HugrView;
use crate::hugr::views::HugrView;
use crate::hugr::{Hugr, Node};
use crate::ops::OpTag;
use crate::ops::{LeafOp, OpTrait, OpType};
Expand Down
3 changes: 1 addition & 2 deletions src/hugr/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ use crate::resource::ResourceSet;
use crate::types::{ClassicType, EdgeKind, SimpleType};
use crate::{Direction, Hugr, Node, Port};

use super::hierarchical_views::{HierarchyView, SiblingGraph};
use super::view::HugrView;
use super::views::{HierarchyView, HugrView, SiblingGraph};

/// Structure keeping track of pre-computed information used in the validation
/// process.
Expand Down
11 changes: 5 additions & 6 deletions src/hugr/view.rs → src/hugr/views.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#![allow(unused)]
//! A Trait for "read-only" HUGRs.
//! Read-only access into HUGR graphs and subgraphs.

use std::iter::FusedIterator;
use std::ops::Deref;
pub mod hierarchy;

use context_iterators::{ContextIterator, IntoContextIterator, MapCtx, MapWithCtx, WithCtx};
pub use hierarchy::{DescendantsGraph, HierarchyView, SiblingGraph};

use context_iterators::{ContextIterator, IntoContextIterator, MapWithCtx};
use itertools::{Itertools, MapInto};
use portgraph::dot::{DotFormat, EdgeStyle, NodeStyle, PortStyle};
use portgraph::{multiportgraph, LinkView, MultiPortGraph, PortView};
Expand Down Expand Up @@ -299,7 +299,6 @@ where
#[inline]
fn get_io(&self, node: Node) -> Option<[Node; 2]> {
let op = self.get_nodetype(node);
let dfp = OpTag::DataflowParent;
if op.tag().is_superset(OpTag::DataflowParent) {
self.children(node).take(2).collect_vec().try_into().ok()
} else {
Expand Down
13 changes: 6 additions & 7 deletions src/hugr/hierarchical_views.rs → src/hugr/views/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use portgraph::{LinkView, PortIndex, PortView};

use crate::{hugr::NodeType, hugr::OpType, Direction, Hugr, Node, Port};

use super::view::sealed::HugrInternals;
use super::{HugrView, NodeMetadata};
use super::{sealed::HugrInternals, HugrView, NodeMetadata};

type FlatRegionGraph<'g, Base> =
portgraph::view::FlatRegion<'g, <Base as HugrInternals>::Portgraph>;
Expand Down Expand Up @@ -345,7 +344,7 @@ where
}
}

/// A common trait for views of a hugr region.
/// A common trait for views of a HUGR hierarchical subgraph.
pub trait HierarchyView<'a>:
HugrView
+ pv::GraphBase<NodeId = Node>
Expand All @@ -359,10 +358,10 @@ pub trait HierarchyView<'a>:
where
for<'g> &'g Self: pv::IntoNeighborsDirected + pv::IntoNodeIdentifiers,
{
/// The base from which the region is derived.
/// The base from which the subgraph is derived.
type Base;

/// Create a region view of a HUGR given a root node.
/// Create a hierarchical view of a HUGR given a root node.
fn new(hugr: &'a Self::Base, root: Node) -> Self;
}

Expand Down Expand Up @@ -404,7 +403,7 @@ where
}
}

impl<'g, Base> super::view::sealed::HugrInternals for SiblingGraph<'g, Base>
impl<'g, Base> super::sealed::HugrInternals for SiblingGraph<'g, Base>
where
Base: HugrInternals,
{
Expand All @@ -421,7 +420,7 @@ where
}
}

impl<'g, Base> super::view::sealed::HugrInternals for DescendantsGraph<'g, Base>
impl<'g, Base> super::sealed::HugrInternals for DescendantsGraph<'g, Base>
where
Base: HugrInternals,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementations of petgraph's traits for Hugr Region views.

use super::{DescendantsGraph, SiblingGraph};
use crate::hugr::view::sealed::HugrInternals;
use crate::hugr::views::sealed::HugrInternals;
use crate::hugr::HugrView;
use crate::ops::OpType;
use crate::types::EdgeKind;
Expand Down

0 comments on commit 383765d

Please sign in to comment.