@@ -14,7 +14,6 @@ use super::{
14
14
use super :: { BuilderWiringError , FunctionBuilder } ;
15
15
16
16
use crate :: {
17
- hugr:: NodeType ,
18
17
ops:: handle:: { ConstID , DataflowOpID , FuncID , NodeHandle } ,
19
18
types:: EdgeKind ,
20
19
} ;
@@ -45,12 +44,7 @@ pub trait Container {
45
44
/// Immutable reference to HUGR being built
46
45
fn hugr ( & self ) -> & Hugr ;
47
46
/// Add an [`OpType`] as the final child of the container.
48
- fn add_child_op ( & mut self , op : impl Into < OpType > ) -> Node {
49
- let parent = self . container_node ( ) ;
50
- self . hugr_mut ( ) . add_node_with_parent ( parent, op)
51
- }
52
- /// Add a [`NodeType`] as the final child of the container.
53
- fn add_child_node ( & mut self , node : NodeType ) -> Node {
47
+ fn add_child_node ( & mut self , node : impl Into < OpType > ) -> Node {
54
48
let parent = self . container_node ( ) ;
55
49
self . hugr_mut ( ) . add_node_with_parent ( parent, node)
56
50
}
@@ -71,8 +65,7 @@ pub trait Container {
71
65
/// This function will return an error if there is an error in adding the
72
66
/// [`OpType::Const`] node.
73
67
fn add_constant ( & mut self , constant : impl Into < ops:: Const > ) -> ConstID {
74
- self . add_child_node ( NodeType :: new_pure ( constant. into ( ) ) )
75
- . into ( )
68
+ self . add_child_node ( constant. into ( ) ) . into ( )
76
69
}
77
70
78
71
/// Add a [`ops::FuncDefn`] node and returns a builder to define the function
@@ -88,13 +81,12 @@ pub trait Container {
88
81
signature : PolyFuncType ,
89
82
) -> Result < FunctionBuilder < & mut Hugr > , BuildError > {
90
83
let body = signature. body ( ) . clone ( ) ;
91
- let f_node = self . add_child_node ( NodeType :: new_pure ( ops:: FuncDefn {
84
+ let f_node = self . add_child_node ( ops:: FuncDefn {
92
85
name : name. into ( ) ,
93
86
signature,
94
- } ) ) ;
87
+ } ) ;
95
88
96
- let db =
97
- DFGBuilder :: create_with_io ( self . hugr_mut ( ) , f_node, body, Some ( ExtensionSet :: new ( ) ) ) ?;
89
+ let db = DFGBuilder :: create_with_io ( self . hugr_mut ( ) , f_node, body) ?;
98
90
Ok ( FunctionBuilder :: from_dfg_builder ( db) )
99
91
}
100
92
@@ -182,29 +174,15 @@ pub trait Dataflow: Container {
182
174
fn input_wires ( & self ) -> Outputs {
183
175
self . input ( ) . outputs ( )
184
176
}
185
- /// Add a dataflow op to the sibling graph, wiring up the `input_wires` to the
177
+ /// Add a dataflow [`OpType`] to the sibling graph, wiring up the `input_wires` to the
186
178
/// incoming ports of the resulting node.
187
179
///
188
180
/// # Errors
189
181
///
190
182
/// Returns a [`BuildError::OperationWiring`] error if the `input_wires` cannot be connected.
191
183
fn add_dataflow_op (
192
184
& mut self ,
193
- op : impl Into < OpType > ,
194
- input_wires : impl IntoIterator < Item = Wire > ,
195
- ) -> Result < BuildHandle < DataflowOpID > , BuildError > {
196
- self . add_dataflow_node ( NodeType :: new_auto ( op) , input_wires)
197
- }
198
-
199
- /// Add a dataflow [`NodeType`] to the sibling graph, wiring up the `input_wires` to the
200
- /// incoming ports of the resulting node.
201
- ///
202
- /// # Errors
203
- ///
204
- /// Returns a [`BuildError::OperationWiring`] error if the `input_wires` cannot be connected.
205
- fn add_dataflow_node (
206
- & mut self ,
207
- nodetype : NodeType ,
185
+ nodetype : impl Into < OpType > ,
208
186
input_wires : impl IntoIterator < Item = Wire > ,
209
187
) -> Result < BuildHandle < DataflowOpID > , BuildError > {
210
188
let outs = add_node_with_wires ( self , nodetype, input_wires) ?;
@@ -297,16 +275,14 @@ pub trait Dataflow: Container {
297
275
fn dfg_builder (
298
276
& mut self ,
299
277
signature : FunctionType ,
300
- input_extensions : Option < ExtensionSet > ,
301
278
input_wires : impl IntoIterator < Item = Wire > ,
302
279
) -> Result < DFGBuilder < & mut Hugr > , BuildError > {
303
280
let op = ops:: DFG {
304
281
signature : signature. clone ( ) ,
305
282
} ;
306
- let nodetype = NodeType :: new ( op, input_extensions. clone ( ) ) ;
307
- let ( dfg_n, _) = add_node_with_wires ( self , nodetype, input_wires) ?;
283
+ let ( dfg_n, _) = add_node_with_wires ( self , op, input_wires) ?;
308
284
309
- DFGBuilder :: create_with_io ( self . hugr_mut ( ) , dfg_n, signature, input_extensions )
285
+ DFGBuilder :: create_with_io ( self . hugr_mut ( ) , dfg_n, signature)
310
286
}
311
287
312
288
/// Return a builder for a [`crate::ops::CFG`] node,
@@ -322,7 +298,6 @@ pub trait Dataflow: Container {
322
298
fn cfg_builder (
323
299
& mut self ,
324
300
inputs : impl IntoIterator < Item = ( Type , Wire ) > ,
325
- input_extensions : impl Into < Option < ExtensionSet > > ,
326
301
output_types : TypeRow ,
327
302
extension_delta : ExtensionSet ,
328
303
) -> Result < CFGBuilder < & mut Hugr > , BuildError > {
@@ -332,13 +307,10 @@ pub trait Dataflow: Container {
332
307
333
308
let ( cfg_node, _) = add_node_with_wires (
334
309
self ,
335
- NodeType :: new (
336
- ops:: CFG {
337
- signature : FunctionType :: new ( inputs. clone ( ) , output_types. clone ( ) )
338
- . with_extension_delta ( extension_delta) ,
339
- } ,
340
- input_extensions. into ( ) ,
341
- ) ,
310
+ ops:: CFG {
311
+ signature : FunctionType :: new ( inputs. clone ( ) , output_types. clone ( ) )
312
+ . with_extension_delta ( extension_delta) ,
313
+ } ,
342
314
input_wires,
343
315
) ?;
344
316
CFGBuilder :: create ( self . hugr_mut ( ) , cfg_node, inputs, output_types)
@@ -348,9 +320,8 @@ pub trait Dataflow: Container {
348
320
/// Adds a [`OpType::LoadConstant`] node.
349
321
fn load_const ( & mut self , cid : & ConstID ) -> Wire {
350
322
let const_node = cid. node ( ) ;
351
- let nodetype = self . hugr ( ) . get_nodetype ( const_node) ;
323
+ let nodetype = self . hugr ( ) . get_optype ( const_node) ;
352
324
let op: ops:: Const = nodetype
353
- . op ( )
354
325
. clone ( )
355
326
. try_into ( )
356
327
. expect ( "ConstID does not refer to Const op." ) ;
@@ -394,7 +365,7 @@ pub trait Dataflow: Container {
394
365
exts : & ExtensionRegistry ,
395
366
) -> Result < Wire , BuildError > {
396
367
let func_node = fid. node ( ) ;
397
- let func_op = self . hugr ( ) . get_nodetype ( func_node) . op ( ) ;
368
+ let func_op = self . hugr ( ) . get_optype ( func_node) ;
398
369
let func_sig = match func_op {
399
370
OpType :: FuncDefn ( ops:: FuncDefn { signature, .. } )
400
371
| OpType :: FuncDecl ( ops:: FuncDecl { signature, .. } ) => signature. clone ( ) ,
@@ -643,26 +614,23 @@ pub trait Dataflow: Container {
643
614
/// invalid edge.
644
615
fn add_node_with_wires < T : Dataflow + ?Sized > (
645
616
data_builder : & mut T ,
646
- nodetype : impl Into < NodeType > ,
617
+ nodetype : impl Into < OpType > ,
647
618
inputs : impl IntoIterator < Item = Wire > ,
648
619
) -> Result < ( Node , usize ) , BuildError > {
649
- let nodetype : NodeType = nodetype. into ( ) ;
620
+ let op = nodetype. into ( ) ;
650
621
// Check there are no row variables, as that would prevent us
651
622
// from indexing into the node's ports in order to wire up
652
- nodetype
653
- . op_signature ( )
623
+ op. dataflow_signature ( )
654
624
. as_ref ( )
655
625
. and_then ( FunctionType :: find_rowvar)
656
626
. map_or ( Ok ( ( ) ) , |( idx, _) | {
657
627
Err ( SignatureError :: RowVarWhereTypeExpected { idx } )
658
628
} ) ?;
659
- let num_outputs = nodetype . op ( ) . value_output_count ( ) ;
660
- let op_node = data_builder. add_child_node ( nodetype . clone ( ) ) ;
629
+ let num_outputs = op . value_output_count ( ) ;
630
+ let op_node = data_builder. add_child_node ( op . clone ( ) ) ;
661
631
662
- wire_up_inputs ( inputs, op_node, data_builder) . map_err ( |error| BuildError :: OperationWiring {
663
- op : nodetype. into_op ( ) ,
664
- error,
665
- } ) ?;
632
+ wire_up_inputs ( inputs, op_node, data_builder)
633
+ . map_err ( |error| BuildError :: OperationWiring { op, error } ) ?;
666
634
667
635
Ok ( ( op_node, num_outputs) )
668
636
}
0 commit comments