@@ -162,10 +162,7 @@ impl FunctionBuilder<Hugr> {
162162 ) -> Result < Self , BuildError > {
163163 let signature: PolyFuncType = signature. into ( ) ;
164164 let body = signature. body ( ) . clone ( ) ;
165- let op = ops:: FuncDefn {
166- signature,
167- name : name. into ( ) ,
168- } ;
165+ let op = ops:: FuncDefn :: new ( name, signature) ;
169166
170167 let base = Hugr :: new_with_entrypoint ( op) . expect ( "FuncDefn entrypoint should be valid" ) ;
171168 let root = base. entrypoint ( ) ;
@@ -187,7 +184,7 @@ impl FunctionBuilder<Hugr> {
187184 } ) ;
188185
189186 // Update the inner input node
190- let types = new_optype. signature . body ( ) . input . clone ( ) ;
187+ let types = new_optype. signature ( ) . body ( ) . input . clone ( ) ;
191188 self . hugr_mut ( ) . replace_op ( inp_node, Input { types } ) ;
192189 let mut new_port = self . hugr_mut ( ) . add_ports ( inp_node, Direction :: Outgoing , 1 ) ;
193190 let new_port = new_port. next ( ) . unwrap ( ) ;
@@ -222,7 +219,7 @@ impl FunctionBuilder<Hugr> {
222219 } ) ;
223220
224221 // Update the inner input node
225- let types = new_optype. signature . body ( ) . output . clone ( ) ;
222+ let types = new_optype. signature ( ) . body ( ) . output . clone ( ) ;
226223 self . hugr_mut ( ) . replace_op ( out_node, Output { types } ) ;
227224 let mut new_port = self . hugr_mut ( ) . add_ports ( out_node, Direction :: Incoming , 1 ) ;
228225 let new_port = new_port. next ( ) . unwrap ( ) ;
@@ -253,22 +250,12 @@ impl FunctionBuilder<Hugr> {
253250 /// Returns a reference to the new optype.
254251 fn update_fn_signature ( & mut self , f : impl FnOnce ( Signature ) -> Signature ) -> & ops:: FuncDefn {
255252 let parent = self . container_node ( ) ;
256- let old_optype = self
257- . hugr ( )
258- . get_optype ( parent)
259- . as_func_defn ( )
260- . expect ( "FunctionBuilder node must be a FuncDefn" ) ;
261- let signature = old_optype. inner_signature ( ) . into_owned ( ) ;
262- let name = old_optype. name . clone ( ) ;
263- self . hugr_mut ( ) . replace_op (
264- parent,
265- ops:: FuncDefn {
266- signature : f ( signature) . into ( ) ,
267- name,
268- } ,
269- ) ;
270253
271- self . hugr ( ) . get_optype ( parent) . as_func_defn ( ) . unwrap ( )
254+ let ops:: OpType :: FuncDefn ( fd) = self . hugr_mut ( ) . optype_mut ( parent) else {
255+ panic ! ( "FunctionBuilder node must be a FuncDefn" )
256+ } ;
257+ * fd. signature_mut ( ) = f ( fd. inner_signature ( ) . into_owned ( ) ) . into ( ) ;
258+ & * fd
272259 }
273260}
274261
@@ -531,8 +518,8 @@ pub(crate) mod test {
531518 let mut module_builder = ModuleBuilder :: new ( ) ;
532519
533520 let ( dfg_node, f_node) = {
534- let mut f_build = module_builder
535- . define_function ( "main" , Signature :: new ( vec ! [ bool_t( ) ] , vec ! [ bool_t ( ) ] ) ) ?;
521+ let mut f_build =
522+ module_builder . define_function ( "main" , Signature :: new_endo ( bool_t ( ) ) ) ?;
536523
537524 let [ i1] = f_build. input_wires_arr ( ) ;
538525 let dfg = f_build. add_hugr_with_wires ( dfg_hugr, [ i1] ) ?;
0 commit comments