@@ -10,7 +10,7 @@ use crate::ssa::ir::value::{Value, ValueId};
10
10
use crate :: ssa:: ssa_gen:: Ssa ;
11
11
use im:: HashMap ;
12
12
use rayon:: prelude:: * ;
13
- use std:: collections:: { BTreeMap , HashSet } ;
13
+ use std:: collections:: { BTreeMap , BTreeSet , HashSet } ;
14
14
use tracing:: trace;
15
15
16
16
impl Ssa {
@@ -73,15 +73,15 @@ fn check_for_underconstrained_values_within_function(
73
73
74
74
context. compute_sets_of_connected_value_ids ( function, all_functions) ;
75
75
76
- let all_brillig_generated_values: HashSet < ValueId > =
76
+ let all_brillig_generated_values: BTreeSet < ValueId > =
77
77
context. brillig_return_to_argument . keys ( ) . copied ( ) . collect ( ) ;
78
78
79
79
let connected_sets_indices =
80
80
context. find_sets_connected_to_function_inputs_or_outputs ( function) ;
81
81
82
82
// Go through each disconnected set, find brillig calls that caused it and form warnings
83
83
for set_index in
84
- HashSet :: from_iter ( 0 ..( context. value_sets . len ( ) ) ) . difference ( & connected_sets_indices)
84
+ BTreeSet :: from_iter ( 0 ..( context. value_sets . len ( ) ) ) . difference ( & connected_sets_indices)
85
85
{
86
86
let current_set = & context. value_sets [ * set_index] ;
87
87
warnings. append ( & mut context. find_disconnecting_brillig_calls_with_results_in_set (
@@ -104,7 +104,7 @@ struct DependencyContext {
104
104
array_elements : HashMap < ValueId , ValueId > ,
105
105
// Map of brillig call ids to sets of the value ids descending
106
106
// from their arguments and results
107
- tainted : HashMap < InstructionId , BrilligTaintedIds > ,
107
+ tainted : BTreeMap < InstructionId , BrilligTaintedIds > ,
108
108
}
109
109
110
110
/// Structure keeping track of value ids descending from Brillig calls'
@@ -434,7 +434,7 @@ impl DependencyContext {
434
434
struct Context {
435
435
visited_blocks : HashSet < BasicBlockId > ,
436
436
block_queue : Vec < BasicBlockId > ,
437
- value_sets : Vec < HashSet < ValueId > > ,
437
+ value_sets : Vec < BTreeSet < ValueId > > ,
438
438
brillig_return_to_argument : HashMap < ValueId , Vec < ValueId > > ,
439
439
brillig_return_to_instruction_id : HashMap < ValueId , InstructionId > ,
440
440
}
@@ -467,15 +467,15 @@ impl Context {
467
467
fn find_sets_connected_to_function_inputs_or_outputs (
468
468
& mut self ,
469
469
function : & Function ,
470
- ) -> HashSet < usize > {
470
+ ) -> BTreeSet < usize > {
471
471
let variable_parameters_and_return_values = function
472
472
. parameters ( )
473
473
. iter ( )
474
474
. chain ( function. returns ( ) )
475
475
. filter ( |id| function. dfg . get_numeric_constant ( * * id) . is_none ( ) )
476
476
. map ( |value_id| function. dfg . resolve ( * value_id) ) ;
477
477
478
- let mut connected_sets_indices: HashSet < usize > = HashSet :: new ( ) ;
478
+ let mut connected_sets_indices: BTreeSet < usize > = BTreeSet :: default ( ) ;
479
479
480
480
// Go through each parameter and each set and check if the set contains the parameter
481
481
// If it's the case, then that set doesn't present an issue
@@ -492,8 +492,8 @@ impl Context {
492
492
/// Find which Brillig calls separate this set from others and return bug warnings about them
493
493
fn find_disconnecting_brillig_calls_with_results_in_set (
494
494
& self ,
495
- current_set : & HashSet < ValueId > ,
496
- all_brillig_generated_values : & HashSet < ValueId > ,
495
+ current_set : & BTreeSet < ValueId > ,
496
+ all_brillig_generated_values : & BTreeSet < ValueId > ,
497
497
function : & Function ,
498
498
) -> Vec < SsaReport > {
499
499
let mut warnings = Vec :: new ( ) ;
@@ -503,7 +503,7 @@ impl Context {
503
503
// Go through all Brillig outputs in the set
504
504
for brillig_output_in_set in intersection {
505
505
// Get the inputs that correspond to the output
506
- let inputs: HashSet < ValueId > =
506
+ let inputs: BTreeSet < ValueId > =
507
507
self . brillig_return_to_argument [ & brillig_output_in_set] . iter ( ) . copied ( ) . collect ( ) ;
508
508
509
509
// Check if any of them are not in the set
@@ -532,7 +532,7 @@ impl Context {
532
532
let instructions = function. dfg [ block] . instructions ( ) ;
533
533
534
534
for instruction in instructions. iter ( ) {
535
- let mut instruction_arguments_and_results = HashSet :: new ( ) ;
535
+ let mut instruction_arguments_and_results = BTreeSet :: new ( ) ;
536
536
537
537
// Insert non-constant instruction arguments
538
538
function. dfg [ * instruction] . for_each_value ( |value_id| {
@@ -638,15 +638,15 @@ impl Context {
638
638
/// Merge all small sets into larger ones based on whether the sets intersect or not
639
639
///
640
640
/// If two small sets have a common ValueId, we merge them into one
641
- fn merge_sets ( current : & [ HashSet < ValueId > ] ) -> Vec < HashSet < ValueId > > {
641
+ fn merge_sets ( current : & [ BTreeSet < ValueId > ] ) -> Vec < BTreeSet < ValueId > > {
642
642
let mut new_set_id: usize = 0 ;
643
- let mut updated_sets: HashMap < usize , HashSet < ValueId > > = HashMap :: new ( ) ;
644
- let mut value_dictionary: HashMap < ValueId , usize > = HashMap :: new ( ) ;
645
- let mut parsed_value_set: HashSet < ValueId > = HashSet :: new ( ) ;
643
+ let mut updated_sets: BTreeMap < usize , BTreeSet < ValueId > > = BTreeMap :: default ( ) ;
644
+ let mut value_dictionary: HashMap < ValueId , usize > = HashMap :: default ( ) ;
645
+ let mut parsed_value_set: BTreeSet < ValueId > = BTreeSet :: default ( ) ;
646
646
647
647
for set in current. iter ( ) {
648
648
// Check if the set has any of the ValueIds we've encountered at previous iterations
649
- let intersection: HashSet < ValueId > =
649
+ let intersection: BTreeSet < ValueId > =
650
650
set. intersection ( & parsed_value_set) . copied ( ) . collect ( ) ;
651
651
parsed_value_set. extend ( set. iter ( ) ) ;
652
652
@@ -663,7 +663,7 @@ impl Context {
663
663
}
664
664
665
665
// If there is an intersection, we have to join the sets
666
- let mut joining_sets_ids: HashSet < usize > =
666
+ let mut joining_sets_ids: BTreeSet < usize > =
667
667
intersection. iter ( ) . map ( |x| value_dictionary[ x] ) . collect ( ) ;
668
668
let mut largest_set_size = usize:: MIN ;
669
669
let mut largest_set_index = usize:: MAX ;
@@ -677,7 +677,7 @@ impl Context {
677
677
joining_sets_ids. remove ( & largest_set_index) ;
678
678
679
679
let mut largest_set =
680
- updated_sets. extract ( & largest_set_index) . expect ( "Set should be in the hashmap" ) . 0 ;
680
+ updated_sets. remove ( & largest_set_index) . expect ( "Set should be in the hashmap" ) ;
681
681
682
682
// For each of other sets that need to be joined
683
683
for set_id in joining_sets_ids. iter ( ) {
@@ -702,7 +702,7 @@ impl Context {
702
702
703
703
/// Parallel version of merge_sets
704
704
/// The sets are merged by chunks, and then the chunks are merged together
705
- fn merge_sets_par ( sets : & [ HashSet < ValueId > ] ) -> Vec < HashSet < ValueId > > {
705
+ fn merge_sets_par ( sets : & [ BTreeSet < ValueId > ] ) -> Vec < BTreeSet < ValueId > > {
706
706
let mut sets = sets. to_owned ( ) ;
707
707
let mut len = sets. len ( ) ;
708
708
let mut prev_len = len + 1 ;
0 commit comments