@@ -27,7 +27,7 @@ use crate::ops::{NamedOp, OpTag, OpTrait, OpType};
2727use crate :: types:: { Signature , Type } ;
2828use crate :: { Hugr , IncomingPort , Node , OutgoingPort , Port , SimpleReplacement } ;
2929
30- use super :: root_checked :: RootCheckable ;
30+ use super :: RootChecked ;
3131
3232/// A non-empty convex subgraph of a HUGR sibling graph.
3333///
@@ -110,15 +110,12 @@ impl<N: HugrNode> SiblingSubgraph<N> {
110110 /// This will return an [`InvalidSubgraph::EmptySubgraph`] error if the
111111 /// subgraph is empty.
112112 pub fn try_new_dataflow_subgraph < ' h , H , Root > (
113- dfg_graph : impl RootCheckable < & ' h H , Root > ,
113+ dfg_graph : RootChecked < & ' h H , Root > ,
114114 ) -> Result < Self , InvalidSubgraph < N > >
115115 where
116116 H : ' h + Clone + HugrView < Node = N > ,
117117 Root : ContainerHandle < N , ChildrenHandle = DataflowOpID > ,
118118 {
119- let Ok ( dfg_graph) = dfg_graph. try_into_checked ( ) else {
120- return Err ( InvalidSubgraph :: NonDataflowRegion ) ;
121- } ;
122119 let dfg_graph = dfg_graph. into_hugr ( ) ;
123120
124121 let parent = HugrView :: entrypoint ( & dfg_graph) ;
@@ -1651,7 +1648,9 @@ mod tests {
16511648 fn construct_simple_replacement ( ) -> Result < ( ) , InvalidSubgraph > {
16521649 let ( mut hugr, func_root) = build_hugr ( ) . unwrap ( ) ;
16531650 let func = hugr. with_entrypoint ( func_root) ;
1654- let sub = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > ( & func) ?;
1651+ let sub = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > (
1652+ RootChecked :: try_new ( & func) . expect ( "Root should be FuncDefn." ) ,
1653+ ) ?;
16551654 assert ! ( sub. validate( & func, Default :: default ( ) ) . is_ok( ) ) ;
16561655
16571656 let empty_dfg = {
@@ -1699,7 +1698,9 @@ mod tests {
16991698 fn test_signature ( ) -> Result < ( ) , InvalidSubgraph > {
17001699 let ( hugr, dfg) = build_hugr ( ) . unwrap ( ) ;
17011700 let func = hugr. with_entrypoint ( dfg) ;
1702- let sub = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > ( & func) ?;
1701+ let sub = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > (
1702+ RootChecked :: try_new ( & func) . expect ( "Root should be FuncDefn." ) ,
1703+ ) ?;
17031704 assert ! ( sub. validate( & func, Default :: default ( ) ) . is_ok( ) ) ;
17041705 assert_eq ! (
17051706 sub. signature( & func) ,
@@ -1732,10 +1733,12 @@ mod tests {
17321733 let ( hugr, func_root) = build_hugr ( ) . unwrap ( ) ;
17331734 let func = hugr. with_entrypoint ( func_root) ;
17341735 assert_eq ! (
1735- SiblingSubgraph :: try_new_dataflow_subgraph:: <_, FuncID <true >>( & func)
1736- . unwrap( )
1737- . nodes( )
1738- . len( ) ,
1736+ SiblingSubgraph :: try_new_dataflow_subgraph:: <_, FuncID <true >>(
1737+ RootChecked :: try_new( & func) . expect( "Root should be FuncDefn." )
1738+ )
1739+ . unwrap( )
1740+ . nodes( )
1741+ . len( ) ,
17391742 4
17401743 ) ;
17411744 }
@@ -1848,8 +1851,10 @@ mod tests {
18481851 fn preserve_signature ( ) {
18491852 let ( hugr, func_root) = build_hugr_classical ( ) . unwrap ( ) ;
18501853 let func_graph = hugr. with_entrypoint ( func_root) ;
1851- let func =
1852- SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > ( & func_graph) . unwrap ( ) ;
1854+ let func = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > (
1855+ RootChecked :: try_new ( & func_graph) . expect ( "Root should be FuncDefn." ) ,
1856+ )
1857+ . unwrap ( ) ;
18531858 let func_defn = hugr. get_optype ( func_root) . as_func_defn ( ) . unwrap ( ) ;
18541859 assert_eq ! ( func_defn. signature( ) , & func. signature( & func_graph) . into( ) ) ;
18551860 }
@@ -1858,8 +1863,10 @@ mod tests {
18581863 fn extract_subgraph ( ) {
18591864 let ( hugr, func_root) = build_hugr ( ) . unwrap ( ) ;
18601865 let func_graph = hugr. with_entrypoint ( func_root) ;
1861- let subgraph =
1862- SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > ( & func_graph) . unwrap ( ) ;
1866+ let subgraph = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , FuncID < true > > (
1867+ RootChecked :: try_new ( & func_graph) . expect ( "Root should be FuncDefn." ) ,
1868+ )
1869+ . unwrap ( ) ;
18631870 let extracted = subgraph. extract_subgraph ( & hugr, "region" ) ;
18641871
18651872 extracted. validate ( ) . unwrap ( ) ;
@@ -1883,7 +1890,10 @@ mod tests {
18831890 . outputs ( ) ;
18841891 let outw = [ outw1] . into_iter ( ) . chain ( outw2) ;
18851892 let h = builder. finish_hugr_with_outputs ( outw) . unwrap ( ) ;
1886- let subg = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , DfgID > ( & h) . unwrap ( ) ;
1893+ let subg = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , DfgID > (
1894+ RootChecked :: try_new ( & h) . expect ( "Root should be DFG." ) ,
1895+ )
1896+ . unwrap ( ) ;
18871897 assert_eq ! ( subg. nodes( ) . len( ) , 2 ) ;
18881898 }
18891899
@@ -2178,9 +2188,10 @@ mod tests {
21782188
21792189 #[ rstest]
21802190 fn test_call_subgraph_from_dfg ( hugr_call_subgraph : Hugr ) {
2181- let subg =
2182- SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , DataflowParentID > ( & hugr_call_subgraph)
2183- . unwrap ( ) ;
2191+ let subg = SiblingSubgraph :: try_new_dataflow_subgraph :: < _ , DataflowParentID > (
2192+ RootChecked :: try_new ( & hugr_call_subgraph) . expect ( "Root should be DFG container." ) ,
2193+ )
2194+ . unwrap ( ) ;
21842195
21852196 assert_eq ! ( subg. function_calls. len( ) , 1 ) ;
21862197 assert_eq ! ( subg. function_calls[ 0 ] . len( ) , 2 ) ;
0 commit comments