@@ -6,13 +6,10 @@ use self::{
6
6
brillig_ir:: artifact:: { BrilligArtifact , Label } ,
7
7
} ;
8
8
use crate :: ssa:: {
9
- ir:: {
10
- function:: { Function , FunctionId , RuntimeType } ,
11
- value:: Value ,
12
- } ,
9
+ ir:: function:: { Function , FunctionId , RuntimeType } ,
13
10
ssa_gen:: Ssa ,
14
11
} ;
15
- use std:: collections:: { HashMap , HashSet } ;
12
+ use std:: collections:: { BTreeSet , HashMap } ;
16
13
17
14
/// Context structure for the brillig pass.
18
15
/// It stores brillig-related data required for brillig generation.
@@ -53,45 +50,11 @@ impl Ssa {
53
50
pub ( crate ) fn to_brillig ( & self , enable_debug_trace : bool ) -> Brillig {
54
51
// Collect all the function ids that are reachable from brillig
55
52
// That means all the functions marked as brillig and ACIR functions called by them
56
- let mut brillig_reachable_function_ids: HashSet < FunctionId > = HashSet :: new ( ) ;
57
-
58
- // Initialize the queue with all the functions marked as brillig
59
- let mut reachability_queue: Vec < FunctionId > = self
53
+ let brillig_reachable_function_ids = self
60
54
. functions
61
55
. iter ( )
62
- . filter_map (
63
- |( id, func) | {
64
- if func. runtime ( ) == RuntimeType :: Brillig {
65
- Some ( * id)
66
- } else {
67
- None
68
- }
69
- } ,
70
- )
71
- . collect ( ) ;
72
-
73
- while let Some ( func_id) = reachability_queue. pop ( ) {
74
- let func = & self . functions [ & func_id] ;
75
- brillig_reachable_function_ids. insert ( func. id ( ) ) ;
76
-
77
- // Explore all functions that are reachable from this function
78
- for ( _, value) in func. dfg . values_iter ( ) {
79
- // All reachable functions appear as literals after defunctionalization of the SSA
80
- let reachable_function = match value {
81
- Value :: Function ( function_id) => function_id,
82
- _ => continue ,
83
- } ;
84
-
85
- // If the function is already reachable by brillig or enqueued, skip it.
86
- if brillig_reachable_function_ids. contains ( reachable_function)
87
- || reachability_queue. contains ( reachable_function)
88
- {
89
- continue ;
90
- }
91
-
92
- reachability_queue. push ( * reachable_function) ;
93
- }
94
- }
56
+ . filter_map ( |( id, func) | ( func. runtime ( ) == RuntimeType :: Brillig ) . then_some ( * id) )
57
+ . collect :: < BTreeSet < _ > > ( ) ;
95
58
96
59
let mut brillig = Brillig :: default ( ) ;
97
60
for brillig_function_id in brillig_reachable_function_ids {
0 commit comments