@@ -5,7 +5,6 @@ use cairo_lang_casm::ap_change::{ApChangeError, ApplyApChange};
5
5
use cairo_lang_sierra:: edit_state:: { put_results, take_args} ;
6
6
use cairo_lang_sierra:: ids:: { FunctionId , VarId } ;
7
7
use cairo_lang_sierra:: program:: { BranchInfo , Function , StatementIdx } ;
8
- use cairo_lang_utils:: try_extract_matches;
9
8
use cairo_lang_utils:: unordered_hash_set:: UnorderedHashSet ;
10
9
use itertools:: zip_eq;
11
10
use thiserror:: Error ;
@@ -22,7 +21,6 @@ use crate::metadata::Metadata;
22
21
use crate :: references:: {
23
22
build_function_parameters_refs, check_types_match, IntroductionPoint ,
24
23
OutputReferenceValueIntroductionPoint , ReferenceValue , ReferencesError , StatementRefs ,
25
- VariableApIndependentLocationInfo ,
26
24
} ;
27
25
use crate :: type_sizes:: TypeSizeMap ;
28
26
@@ -205,8 +203,7 @@ impl ProgramAnnotations {
205
203
// Check if the variable doesn't match on type, expression or stack information.
206
204
if !( actual_ref. ty == expected_ref. ty
207
205
&& actual_ref. expression == expected_ref. expression
208
- && actual_ref. ap_independent_location_info
209
- == expected_ref. ap_independent_location_info )
206
+ && actual_ref. stack_idx == expected_ref. stack_idx )
210
207
{
211
208
return false ;
212
209
}
@@ -273,13 +270,10 @@ impl ProgramAnnotations {
273
270
error,
274
271
} ) ?,
275
272
ty : ref_value. ty . clone ( ) ,
276
- ap_independent_location_info : match & ref_value. ap_independent_location_info {
277
- VariableApIndependentLocationInfo :: ContinuousStack ( _)
278
- if branch_changes. clear_old_stack =>
279
- {
280
- VariableApIndependentLocationInfo :: Other
281
- }
282
- other => other. clone ( ) ,
273
+ stack_idx : if branch_changes. clear_old_stack {
274
+ None
275
+ } else {
276
+ ref_value. stack_idx
283
277
} ,
284
278
introduction_point : ref_value. introduction_point . clone ( ) ,
285
279
} ,
@@ -292,7 +286,7 @@ impl ProgramAnnotations {
292
286
branch_changes. refs . into_iter ( ) . map ( |value| ReferenceValue {
293
287
expression : value. expression ,
294
288
ty : value. ty ,
295
- ap_independent_location_info : value. ap_independent_location_info ,
289
+ stack_idx : value. stack_idx ,
296
290
introduction_point : match value. introduction_point {
297
291
OutputReferenceValueIntroductionPoint :: New ( output_idx) => {
298
292
IntroductionPoint {
@@ -317,34 +311,18 @@ impl ProgramAnnotations {
317
311
// Since some variables on the stack may have been consumed by the libfunc, we need to
318
312
// find the new stack size. This is done by searching from the bottom of the stack until we
319
313
// find a missing variable.
320
- let available_stack_indices: UnorderedHashSet < _ > = refs
321
- . values ( )
322
- . flat_map ( |r| {
323
- try_extract_matches ! (
324
- r. ap_independent_location_info,
325
- VariableApIndependentLocationInfo :: ContinuousStack
326
- )
327
- } )
328
- . collect ( ) ;
314
+ let available_stack_indices: UnorderedHashSet < _ > =
315
+ refs. values ( ) . flat_map ( |r| r. stack_idx ) . collect ( ) ;
329
316
let new_stack_size_opt = ( 0 ..branch_changes. new_stack_size )
330
317
. find ( |i| !available_stack_indices. contains ( & ( branch_changes. new_stack_size - 1 - i) ) ) ;
331
318
let stack_size = if let Some ( new_stack_size) = new_stack_size_opt {
332
319
// The number of stack elements which were removed.
333
320
let stack_removal = branch_changes. new_stack_size - new_stack_size;
334
321
for r in refs. values_mut ( ) {
335
- r. ap_independent_location_info = match & r. ap_independent_location_info {
336
- VariableApIndependentLocationInfo :: ContinuousStack ( stack_idx) => {
337
- // Subtract the number of stack elements removed. If the result is negative,
338
- // `stack_idx` is set to `None` and the variable is removed from the stack.
339
- match stack_idx. checked_sub ( stack_removal) {
340
- Some ( new_stack_idx) => {
341
- VariableApIndependentLocationInfo :: ContinuousStack ( new_stack_idx)
342
- }
343
- None => VariableApIndependentLocationInfo :: Other ,
344
- }
345
- }
346
- other => other. clone ( ) ,
347
- } ;
322
+ // Subtract the number of stack elements removed. If the result is negative,
323
+ // `stack_idx` is set to `None` and the variable is removed from the stack.
324
+ r. stack_idx =
325
+ r. stack_idx . and_then ( |stack_idx| stack_idx. checked_sub ( stack_removal) ) ;
348
326
}
349
327
new_stack_size
350
328
} else {
@@ -456,12 +434,8 @@ fn test_var_consistency(
456
434
expected : & ReferenceValue ,
457
435
ap_tracking_enabled : bool ,
458
436
) -> bool {
459
- // If the variable is on the stack, or is local, it can always be merged.
460
- if matches ! (
461
- actual. ap_independent_location_info,
462
- VariableApIndependentLocationInfo :: ContinuousStack ( _)
463
- | VariableApIndependentLocationInfo :: Local
464
- ) {
437
+ // If the variable is on the stack, it can always be merged.
438
+ if actual. stack_idx . is_some ( ) {
465
439
return true ;
466
440
}
467
441
// If the variable is not ap-dependent it can always be merged.
0 commit comments