@@ -400,7 +400,10 @@ impl<T: Copy + Clone + PartialEq + Eq + Hash> EdgeClassifier<T> {
400
400
#[ cfg( test) ]
401
401
pub ( crate ) mod test {
402
402
use super :: * ;
403
- use crate :: builder:: { BuildError , CFGBuilder , Container , Dataflow , ModuleBuilder } ;
403
+ use crate :: builder:: {
404
+ BuildError , CFGBuilder , Container , Dataflow , DataflowSubContainer , HugrBuilder , HugrMutRef ,
405
+ ModuleBuilder , SubContainer ,
406
+ } ;
404
407
use crate :: ops:: {
405
408
handle:: { BasicBlockID , CfgID , ConstID , NodeHandle } ,
406
409
ConstValue ,
@@ -430,8 +433,8 @@ pub(crate) mod test {
430
433
// \-> right -/ \-<--<-/
431
434
let mut module_builder = ModuleBuilder :: new ( ) ;
432
435
let main = module_builder. declare ( "main" , Signature :: new_df ( vec ! [ NAT ] , type_row ! [ NAT ] ) ) ?;
433
- let pred_const = module_builder. constant ( ConstValue :: simple_predicate ( 0 , 2 ) ) ?; // Nothing here cares which
434
- let const_unit = module_builder. constant ( ConstValue :: simple_unary_predicate ( ) ) ?;
436
+ let pred_const = module_builder. add_constant ( ConstValue :: simple_predicate ( 0 , 2 ) ) ?; // Nothing here cares which
437
+ let const_unit = module_builder. add_constant ( ConstValue :: simple_unary_predicate ( ) ) ?;
435
438
436
439
let mut func_builder = module_builder. define_function ( & main) ?;
437
440
let [ int] = func_builder. input_wires_arr ( ) ;
@@ -448,11 +451,10 @@ pub(crate) mod test {
448
451
cfg_builder. branch ( & merge, 0 , & head) ?;
449
452
let exit = cfg_builder. exit_block ( ) ;
450
453
cfg_builder. branch ( & tail, 0 , & exit) ?;
451
- let cfg_id = cfg_builder. finish ( ) ;
454
+ let cfg_id = cfg_builder. finish_sub_container ( ) ? ;
452
455
453
456
func_builder. finish_with_outputs ( cfg_id. outputs ( ) ) ?;
454
-
455
- let h = module_builder. finish ( ) ?;
457
+ let h = module_builder. finish_hugr ( ) ?;
456
458
457
459
let ( entry, exit) = ( entry. node ( ) , exit. node ( ) ) ;
458
460
let ( split, merge, head, tail) = ( split. node ( ) , merge. node ( ) , head. node ( ) , tail. node ( ) ) ;
@@ -483,8 +485,8 @@ pub(crate) mod test {
483
485
// the conditional and the loop to indicate the boundary, so we cannot separate them.
484
486
let mut module_builder = ModuleBuilder :: new ( ) ;
485
487
let main = module_builder. declare ( "main" , Signature :: new_df ( vec ! [ NAT ] , type_row ! [ NAT ] ) ) ?;
486
- let pred_const = module_builder. constant ( ConstValue :: simple_predicate ( 0 , 2 ) ) ?; // Nothing here cares which
487
- let const_unit = module_builder. constant ( ConstValue :: simple_unary_predicate ( ) ) ?;
488
+ let pred_const = module_builder. add_constant ( ConstValue :: simple_predicate ( 0 , 2 ) ) ?; // Nothing here cares which
489
+ let const_unit = module_builder. add_constant ( ConstValue :: simple_unary_predicate ( ) ) ?;
488
490
489
491
let mut func_builder = module_builder. define_function ( & main) ?;
490
492
let [ int] = func_builder. input_wires_arr ( ) ;
@@ -499,11 +501,11 @@ pub(crate) mod test {
499
501
cfg_builder. branch ( & merge, 0 , & tail) ?; // trivial "loop body"
500
502
let exit = cfg_builder. exit_block ( ) ;
501
503
cfg_builder. branch ( & tail, 0 , & exit) ?;
502
- let cfg_id = cfg_builder. finish ( ) ;
504
+ let cfg_id = cfg_builder. finish_sub_container ( ) ? ;
503
505
504
506
func_builder. finish_with_outputs ( cfg_id. outputs ( ) ) ?;
505
507
506
- let h = module_builder. finish ( ) ?;
508
+ let h = module_builder. finish_hugr ( ) ?;
507
509
508
510
let ( entry, exit) = ( entry. node ( ) , exit. node ( ) ) ;
509
511
let ( merge, tail) = ( merge. node ( ) , tail. node ( ) ) ;
@@ -602,7 +604,7 @@ pub(crate) mod test {
602
604
Ok ( ( ) )
603
605
}
604
606
605
- fn n_identity < T : Dataflow > (
607
+ fn n_identity < T : DataflowSubContainer > (
606
608
mut dataflow_builder : T ,
607
609
pred_const : & ConstID ,
608
610
) -> Result < T :: ContainerHandle , BuildError > {
@@ -611,8 +613,8 @@ pub(crate) mod test {
611
613
dataflow_builder. finish_with_outputs ( [ u] . into_iter ( ) . chain ( w) )
612
614
}
613
615
614
- fn build_if_then_else_merge (
615
- cfg : & mut CFGBuilder ,
616
+ fn build_if_then_else_merge < T : HugrMutRef > (
617
+ cfg : & mut CFGBuilder < T > ,
616
618
const_pred : & ConstID ,
617
619
unit_const : & ConstID ,
618
620
) -> Result < ( BasicBlockID , BasicBlockID ) , BuildError > {
@@ -624,8 +626,8 @@ pub(crate) mod test {
624
626
Ok ( ( split, merge) )
625
627
}
626
628
627
- fn build_then_else_merge_from_if (
628
- cfg : & mut CFGBuilder ,
629
+ fn build_then_else_merge_from_if < T : HugrMutRef > (
630
+ cfg : & mut CFGBuilder < T > ,
629
631
unit_const : & ConstID ,
630
632
split : BasicBlockID ,
631
633
) -> Result < BasicBlockID , BuildError > {
@@ -649,8 +651,8 @@ pub(crate) mod test {
649
651
}
650
652
651
653
// Returns loop tail - caller must link header to tail, and provide 0th successor of tail
652
- fn build_loop_from_header (
653
- cfg : & mut CFGBuilder ,
654
+ fn build_loop_from_header < T : HugrMutRef > (
655
+ cfg : & mut CFGBuilder < T > ,
654
656
const_pred : & ConstID ,
655
657
header : BasicBlockID ,
656
658
) -> Result < BasicBlockID , BuildError > {
@@ -663,8 +665,8 @@ pub(crate) mod test {
663
665
}
664
666
665
667
// Result is header and tail. Caller must provide 0th successor of header (linking to tail), and 0th successor of tail.
666
- fn build_loop (
667
- cfg : & mut CFGBuilder ,
668
+ fn build_loop < T : HugrMutRef > (
669
+ cfg : & mut CFGBuilder < T > ,
668
670
const_pred : & ConstID ,
669
671
unit_const : & ConstID ,
670
672
) -> Result < ( BasicBlockID , BasicBlockID ) , BuildError > {
@@ -684,8 +686,8 @@ pub(crate) mod test {
684
686
685
687
let mut module_builder = ModuleBuilder :: new ( ) ;
686
688
let main = module_builder. declare ( "main" , Signature :: new_df ( vec ! [ NAT ] , type_row ! [ NAT ] ) ) ?;
687
- let pred_const = module_builder. constant ( ConstValue :: simple_predicate ( 0 , 2 ) ) ?; // Nothing here cares which
688
- let const_unit = module_builder. constant ( ConstValue :: simple_unary_predicate ( ) ) ?;
689
+ let pred_const = module_builder. add_constant ( ConstValue :: simple_predicate ( 0 , 2 ) ) ?; // Nothing here cares which
690
+ let const_unit = module_builder. add_constant ( ConstValue :: simple_unary_predicate ( ) ) ?;
689
691
690
692
let mut func_builder = module_builder. define_function ( & main) ?;
691
693
let [ int] = func_builder. input_wires_arr ( ) ;
@@ -713,11 +715,11 @@ pub(crate) mod test {
713
715
cfg_builder. branch ( & entry, 0 , & head) ?;
714
716
cfg_builder. branch ( & tail, 0 , & exit) ?;
715
717
716
- let cfg_id = cfg_builder. finish ( ) ;
718
+ let cfg_id = cfg_builder. finish_sub_container ( ) ? ;
717
719
718
720
func_builder. finish_with_outputs ( cfg_id. outputs ( ) ) ?;
719
721
720
- let h = module_builder. finish ( ) ?;
722
+ let h = module_builder. finish_hugr ( ) ?;
721
723
722
724
Ok ( ( h, * cfg_id. handle ( ) , head, tail) )
723
725
}
0 commit comments