@@ -30,7 +30,6 @@ use cairo_lang_sierra_to_casm::metadata::{
3030use cairo_lang_sierra_type_size:: ProgramRegistryInfo ;
3131use cairo_lang_utils:: casts:: IntoOrPanic ;
3232use cairo_lang_utils:: ordered_hash_map:: OrderedHashMap ;
33- use cairo_lang_utils:: unordered_hash_map:: UnorderedHashMap ;
3433use cairo_lang_utils:: unordered_hash_set:: UnorderedHashSet ;
3534use cairo_vm:: types:: builtin_name:: BuiltinName ;
3635use thiserror:: Error ;
@@ -331,7 +330,7 @@ struct EntryCodeHelper {
331330 ctx : CasmBuilder ,
332331 config : EntryCodeConfig ,
333332 input_builtin_vars : OrderedHashMap < BuiltinName , Var > ,
334- builtin_ty_to_vm_name : UnorderedHashMap < GenericTypeId , BuiltinName > ,
333+ builtin_ty_to_vm_name : OrderedHashMap < GenericTypeId , BuiltinName > ,
335334 builtins : Vec < BuiltinName > ,
336335 got_segment_arena : bool ,
337336 has_post_calculation_loop : bool ,
@@ -348,7 +347,17 @@ impl EntryCodeHelper {
348347 ctx : CasmBuilder :: default ( ) ,
349348 config,
350349 input_builtin_vars : OrderedHashMap :: default ( ) ,
351- builtin_ty_to_vm_name : UnorderedHashMap :: default ( ) ,
350+ builtin_ty_to_vm_name : OrderedHashMap :: from_iter ( [
351+ ( PedersenType :: ID , BuiltinName :: pedersen) ,
352+ ( RangeCheckType :: ID , BuiltinName :: range_check) ,
353+ ( BitwiseType :: ID , BuiltinName :: bitwise) ,
354+ ( EcOpType :: ID , BuiltinName :: ec_op) ,
355+ ( PoseidonType :: ID , BuiltinName :: poseidon) ,
356+ ( RangeCheck96Type :: ID , BuiltinName :: range_check96) ,
357+ ( AddModType :: ID , BuiltinName :: add_mod) ,
358+ ( MulModType :: ID , BuiltinName :: mul_mod) ,
359+ ( SegmentArenaType :: ID , BuiltinName :: segment_arena) ,
360+ ] ) ,
352361 builtins : vec ! [ ] ,
353362 got_segment_arena : false ,
354363 has_post_calculation_loop : false ,
@@ -361,24 +370,16 @@ impl EntryCodeHelper {
361370 /// Processes the builtins required for the function parameters.
362371 fn process_builtins ( & mut self , param_types : & [ ( GenericTypeId , i16 ) ] ) {
363372 let mut builtin_offset = 3 ;
364- for ( builtin_name, builtin_ty) in [
365- ( BuiltinName :: mul_mod, MulModType :: ID ) ,
366- ( BuiltinName :: add_mod, AddModType :: ID ) ,
367- ( BuiltinName :: range_check96, RangeCheck96Type :: ID ) ,
368- ( BuiltinName :: poseidon, PoseidonType :: ID ) ,
369- ( BuiltinName :: ec_op, EcOpType :: ID ) ,
370- ( BuiltinName :: bitwise, BitwiseType :: ID ) ,
371- ( BuiltinName :: range_check, RangeCheckType :: ID ) ,
372- ( BuiltinName :: pedersen, PedersenType :: ID ) ,
373- ] {
374- if param_types. iter ( ) . any ( |( ty, _) | ty == & builtin_ty) {
373+
374+ // Process all builtins except the segment arena in reverse order.
375+ for ( builtin_ty, builtin_name) in self . builtin_ty_to_vm_name . iter ( ) . rev ( ) . skip ( 1 ) {
376+ if param_types. iter ( ) . any ( |( ty, _) | ty == builtin_ty) {
375377 self . input_builtin_vars . insert (
376- builtin_name,
378+ * builtin_name,
377379 self . ctx . add_var ( CellExpression :: Deref ( deref ! ( [ fp - builtin_offset] ) ) ) ,
378380 ) ;
379- self . builtin_ty_to_vm_name . insert ( builtin_ty, builtin_name) ;
380381 builtin_offset += 1 ;
381- self . builtins . push ( builtin_name) ;
382+ self . builtins . push ( * builtin_name) ;
382383 }
383384 }
384385 if !self . config . testing {
@@ -421,7 +422,6 @@ impl EntryCodeHelper {
421422 }
422423 // Adding the segment arena to the builtins var map.
423424 self . input_builtin_vars . insert ( BuiltinName :: segment_arena, segment_arena) ;
424- self . builtin_ty_to_vm_name . insert ( SegmentArenaType :: ID , BuiltinName :: segment_arena) ;
425425 }
426426 let mut unallocated_count = 0 ;
427427 let mut param_index = 0 ;
0 commit comments