@@ -233,33 +233,32 @@ where
233233 for ( branch_index, branch_signature) in
234234 libfunc_signature. branch_signatures . iter ( ) . enumerate ( )
235235 {
236+ if libfunc_signature. branch_signatures . len ( ) > 1 {
237+ let branch_align_libfunc_id = branch_align_libfunc
238+ . get_or_init ( || {
239+ self . push_libfunc_declaration ( ConcreteLibfuncLongId {
240+ generic_id : GenericLibfuncId :: from_string ( BranchAlignLibfunc :: STR_ID ) ,
241+ generic_args : Vec :: new ( ) ,
242+ } )
243+ . clone ( )
244+ } )
245+ . clone ( ) ;
246+ self . program
247+ . statements
248+ . push ( Statement :: Invocation ( Invocation {
249+ libfunc_id : branch_align_libfunc_id,
250+ args : Vec :: new ( ) ,
251+ branches : vec ! [ BranchInfo {
252+ target: BranchTarget :: Fallthrough ,
253+ results: Vec :: new( ) ,
254+ } ] ,
255+ } ) ) ;
256+ }
257+
236258 let branch_target = match branch_index {
237259 0 => BranchTarget :: Fallthrough ,
238260 _ => {
239261 let statement_idx = StatementIdx ( self . program . statements . len ( ) + 1 ) ;
240- let branch_align_libfunc_id = branch_align_libfunc
241- . get_or_init ( || {
242- self . push_libfunc_declaration ( ConcreteLibfuncLongId {
243- generic_id : GenericLibfuncId :: from_string (
244- BranchAlignLibfunc :: STR_ID ,
245- ) ,
246- generic_args : Vec :: new ( ) ,
247- } )
248- . clone ( )
249- } )
250- . clone ( ) ;
251-
252- self . program
253- . statements
254- . push ( Statement :: Invocation ( Invocation {
255- libfunc_id : branch_align_libfunc_id,
256- args : Vec :: new ( ) ,
257- branches : vec ! [ BranchInfo {
258- target: BranchTarget :: Fallthrough ,
259- results: Vec :: new( ) ,
260- } ] ,
261- } ) ) ;
262-
263262 BranchTarget :: Statement ( statement_idx)
264263 }
265264 } ;
@@ -380,7 +379,7 @@ where
380379 . clone ( ) ;
381380
382381 let id = ConcreteTypeId :: new ( self . program . type_declarations . len ( ) as u64 ) ;
383- self . program . type_declarations . push ( dbg ! ( TypeDeclaration {
382+ self . program . type_declarations . push ( TypeDeclaration {
384383 id,
385384 long_id : type_info. long_id ,
386385 declared_type_info : Some ( DeclaredTypeInfo {
@@ -389,7 +388,7 @@ where
389388 duplicatable : type_info. duplicatable ,
390389 zero_sized : type_info. zero_sized ,
391390 } ) ,
392- } ) ) ;
391+ } ) ;
393392
394393 & self . program . type_declarations . last ( ) . unwrap ( ) . id
395394 }
@@ -450,10 +449,6 @@ where
450449 . iter ( )
451450 . find_map ( |type_declaration| {
452451 ( type_declaration. id == id) . then ( || {
453- dbg ! (
454- & type_declaration. long_id,
455- type_declaration. declared_type_info. as_ref( )
456- ) ;
457452 let declared_type_info = type_declaration. declared_type_info . as_ref ( ) . unwrap ( ) ;
458453 TypeInfo {
459454 long_id : type_declaration. long_id . clone ( ) ,
@@ -480,12 +475,14 @@ mod test {
480475 use cairo_lang_sierra:: extensions:: {
481476 array:: ArrayNewLibfunc ,
482477 bounded_int:: BoundedIntTrimLibfunc ,
478+ bytes31:: Bytes31FromFelt252Trait ,
483479 int:: {
484480 signed:: { Sint8Traits , SintDiffLibfunc } ,
485481 unsigned:: { Uint32Type , Uint64Traits , Uint8Type } ,
486482 unsigned128:: U128GuaranteeMulLibfunc ,
487483 IntConstLibfunc ,
488484 } ,
485+ try_from_felt252:: TryFromFelt252Libfunc ,
489486 } ;
490487
491488 #[ test]
@@ -533,4 +530,11 @@ mod test {
533530 } ;
534531 println ! ( "{program}" ) ;
535532 }
533+
534+ #[ test]
535+ fn sierra_generator_branch_align ( ) {
536+ let program =
537+ SierraGenerator :: < TryFromFelt252Libfunc < Bytes31FromFelt252Trait > > :: default ( ) . build ( & [ ] ) ;
538+ println ! ( "{program}" ) ;
539+ }
536540}
0 commit comments