@@ -136,13 +136,14 @@ pub fn compute_costs<
136
136
} ) ;
137
137
}
138
138
139
- context. prepare_wallet ( specific_cost_context) ?;
139
+ let prepare_wallet_order = context. prepare_wallet_order ( ) ?;
140
+ context. prepare_wallet ( & prepare_wallet_order, specific_cost_context) ;
140
141
141
142
// Compute the excess cost and the corresponding target value for each statement.
142
143
context. target_values = context. compute_target_values ( specific_cost_context) ?;
143
144
144
145
// Recompute the wallet values for each statement, after setting the target values.
145
- context. prepare_wallet ( specific_cost_context) ? ;
146
+ context. prepare_wallet ( & prepare_wallet_order , specific_cost_context) ;
146
147
147
148
// Check that enforcing the wallet values succeeded.
148
149
for ( idx, value) in enforced_wallet_values. iter ( ) {
@@ -448,34 +449,31 @@ impl<CostType: CostTypeTrait> CostContext<'_, CostType> {
448
449
/// Prepares the values for [Self::wallet_at].
449
450
fn prepare_wallet < SpecificCostContext : SpecificCostContextTrait < CostType > > (
450
451
& mut self ,
452
+ order : & [ StatementIdx ] ,
451
453
specific_cost_context : & SpecificCostContext ,
452
- ) -> Result < ( ) , CostError > {
453
- let rev_topological_order = compute_reverse_topological_order (
454
- self . program . statements . len ( ) ,
455
- true ,
456
- |current_idx| {
457
- match & self . program . get_statement ( current_idx) . unwrap ( ) {
458
- Statement :: Return ( _) => {
459
- // Return has no dependencies.
460
- vec ! [ ]
461
- }
462
- Statement :: Invocation ( invocation) => get_branch_requirements_dependencies (
463
- current_idx,
464
- invocation,
465
- & self . branch_costs [ current_idx. 0 ] ,
466
- ) ,
467
- }
468
- } ,
469
- ) ?;
470
-
454
+ ) {
471
455
self . costs . resize ( self . program . statements . len ( ) , Default :: default ( ) ) ;
472
- for current_idx in rev_topological_order {
456
+ for idx in order {
473
457
// The computation of the dependencies was completed.
474
- self . costs [ current_idx. 0 ] =
475
- self . no_cache_compute_wallet_at ( & current_idx, specific_cost_context) ;
458
+ self . costs [ idx. 0 ] = self . no_cache_compute_wallet_at ( idx, specific_cost_context) ;
476
459
}
460
+ }
477
461
478
- Ok ( ( ) )
462
+ /// Returns the order for the preparation of the wallet values for [Self::prepare_wallet].
463
+ fn prepare_wallet_order ( & self ) -> Result < Vec < StatementIdx > , CostError > {
464
+ compute_reverse_topological_order ( self . program . statements . len ( ) , true , |current_idx| {
465
+ match & self . program . get_statement ( current_idx) . unwrap ( ) {
466
+ Statement :: Return ( _) => {
467
+ // Return has no dependencies.
468
+ vec ! [ ]
469
+ }
470
+ Statement :: Invocation ( invocation) => get_branch_requirements_dependencies (
471
+ current_idx,
472
+ invocation,
473
+ & self . branch_costs [ current_idx. 0 ] ,
474
+ ) ,
475
+ }
476
+ } )
479
477
}
480
478
481
479
/// Helper function for `prepare_wallet()`.
0 commit comments