@@ -8,14 +8,9 @@ use std::marker::PhantomData;
88
99use crate :: hugr:: internal:: HugrMutInternals ;
1010use crate :: hugr:: { HugrView , ValidationError } ;
11- use crate :: ops:: { self , OpParent } ;
12- use crate :: ops:: { DataflowParent , Input , Output } ;
13- use crate :: { Direction , IncomingPort , OutgoingPort , Wire } ;
14-
11+ use crate :: ops:: { self , DataflowParent , FuncDefn , Input , OpParent , Output } ;
1512use crate :: types:: { PolyFuncType , Signature , Type } ;
16-
17- use crate :: Node ;
18- use crate :: { Hugr , hugr:: HugrMut } ;
13+ use crate :: { Direction , Hugr , IncomingPort , Node , OutgoingPort , Visibility , Wire , hugr:: HugrMut } ;
1914
2015/// Builder for a [`ops::DFG`] node.
2116#[ derive( Debug , Clone , PartialEq ) ]
@@ -152,17 +147,35 @@ impl<B, T> DFGWrapper<B, T> {
152147pub type FunctionBuilder < B > = DFGWrapper < B , BuildHandle < FuncID < true > > > ;
153148
154149impl FunctionBuilder < Hugr > {
155- /// Initialize a builder for a `FuncDefn` rooted HUGR
150+ /// Initialize a builder for a [`FuncDefn`](ops::FuncDefn)-rooted HUGR;
151+ /// the function will be private. (See also [Self::new_vis].)
152+ ///
156153 /// # Errors
157154 ///
158155 /// Error in adding DFG child nodes.
159156 pub fn new (
160157 name : impl Into < String > ,
161158 signature : impl Into < PolyFuncType > ,
162159 ) -> Result < Self , BuildError > {
163- let signature: PolyFuncType = signature. into ( ) ;
164- let body = signature. body ( ) . clone ( ) ;
165- let op = ops:: FuncDefn :: new ( name, signature) ;
160+ Self :: new_with_op ( FuncDefn :: new ( name, signature) )
161+ }
162+
163+ /// Initialize a builder for a FuncDefn-rooted HUGR, with the specified
164+ /// [Visibility].
165+ ///
166+ /// # Errors
167+ ///
168+ /// Error in adding DFG child nodes.
169+ pub fn new_vis (
170+ name : impl Into < String > ,
171+ signature : impl Into < PolyFuncType > ,
172+ visibility : Visibility ,
173+ ) -> Result < Self , BuildError > {
174+ Self :: new_with_op ( FuncDefn :: new_vis ( name, signature, visibility) )
175+ }
176+
177+ fn new_with_op ( op : FuncDefn ) -> Result < Self , BuildError > {
178+ let body = op. signature ( ) . body ( ) . clone ( ) ;
166179
167180 let base = Hugr :: new_with_entrypoint ( op) . expect ( "FuncDefn entrypoint should be valid" ) ;
168181 let root = base. entrypoint ( ) ;
@@ -437,7 +450,7 @@ pub(crate) mod test {
437450 error: BuilderWiringError :: NoCopyLinear { typ, .. } ,
438451 ..
439452 } )
440- if typ == qb_t( )
453+ if * typ == qb_t( )
441454 ) ;
442455 }
443456
0 commit comments