@@ -965,54 +965,62 @@ impl<'a> ConstFoldingContext<'a> {
965965 let index = self . as_int ( info. inputs [ 1 ] . var_id ) ?. to_usize ( ) ?;
966966 if let Some ( VarInfo :: Snapshot ( arr_info) ) = self . var_info . get ( & info. inputs [ 0 ] . var_id ) {
967967 if let VarInfo :: Array ( infos) = arr_info. as_ref ( ) {
968- if let Some ( Some ( output_var_info) ) = infos. get ( index) {
969- let arm = & info. arms [ 0 ] ;
970- let output_var_info = output_var_info. clone ( ) ;
971- let box_info =
972- VarInfo :: Box ( VarInfo :: Snapshot ( output_var_info. clone ( ) . into ( ) ) . into ( ) ) ;
973- self . var_info . insert ( arm. var_ids [ 0 ] , box_info) ;
974- if let VarInfo :: Const ( value) = output_var_info {
975- let value_ty = value. ty ( db) . ok ( ) ?;
976- let value_box_ty = corelib:: core_box_ty ( db, value_ty) ;
977- let location = info. location ;
978- let boxed_var =
979- Variable :: with_default_context ( db, value_box_ty, location) ;
980- let boxed = self . variables . alloc ( boxed_var. clone ( ) ) ;
981- let unused_boxed = self . variables . alloc ( boxed_var) ;
982- let snapped = self . variables . alloc ( Variable :: with_default_context (
983- db,
984- TypeLongId :: Snapshot ( value_box_ty) . intern ( db) ,
985- location,
986- ) ) ;
968+ match infos. get ( index) {
969+ Some ( Some ( output_var_info) ) => {
970+ let arm = & info. arms [ 0 ] ;
971+ let output_var_info = output_var_info. clone ( ) ;
972+ let box_info = VarInfo :: Box (
973+ VarInfo :: Snapshot ( output_var_info. clone ( ) . into ( ) ) . into ( ) ,
974+ ) ;
975+ self . var_info . insert ( arm. var_ids [ 0 ] , box_info) ;
976+ if let VarInfo :: Const ( value) = output_var_info {
977+ let value_ty = value. ty ( db) . ok ( ) ?;
978+ let value_box_ty = corelib:: core_box_ty ( db, value_ty) ;
979+ let location = info. location ;
980+ let boxed_var =
981+ Variable :: with_default_context ( db, value_box_ty, location) ;
982+ let boxed = self . variables . alloc ( boxed_var. clone ( ) ) ;
983+ let unused_boxed = self . variables . alloc ( boxed_var) ;
984+ let snapped = self . variables . alloc ( Variable :: with_default_context (
985+ db,
986+ TypeLongId :: Snapshot ( value_box_ty) . intern ( db) ,
987+ location,
988+ ) ) ;
989+ return Some ( (
990+ vec ! [
991+ Statement :: Const ( StatementConst {
992+ value: ConstValue :: Boxed ( value. into( ) ) ,
993+ output: boxed,
994+ } ) ,
995+ Statement :: Snapshot ( StatementSnapshot {
996+ input: VarUsage { var_id: boxed, location } ,
997+ outputs: [ unused_boxed, snapped] ,
998+ } ) ,
999+ Statement :: Call ( StatementCall {
1000+ function: self
1001+ . box_forward_snapshot
1002+ . concretize(
1003+ db,
1004+ vec![ GenericArgumentId :: Type ( value_ty) ] ,
1005+ )
1006+ . lowered( db) ,
1007+ inputs: vec![ VarUsage { var_id: snapped, location } ] ,
1008+ with_coupon: false ,
1009+ outputs: vec![ arm. var_ids[ 0 ] ] ,
1010+ location: info. location,
1011+ } ) ,
1012+ ] ,
1013+ BlockEnd :: Goto ( arm. block_id , Default :: default ( ) ) ,
1014+ ) ) ;
1015+ }
1016+ }
1017+ None => {
9871018 return Some ( (
988- vec ! [
989- Statement :: Const ( StatementConst {
990- value: ConstValue :: Boxed ( value. into( ) ) ,
991- output: boxed,
992- } ) ,
993- Statement :: Snapshot ( StatementSnapshot {
994- input: VarUsage { var_id: boxed, location } ,
995- outputs: [ unused_boxed, snapped] ,
996- } ) ,
997- Statement :: Call ( StatementCall {
998- function: self
999- . box_forward_snapshot
1000- . concretize( db, vec![ GenericArgumentId :: Type ( value_ty) ] )
1001- . lowered( db) ,
1002- inputs: vec![ VarUsage { var_id: snapped, location } ] ,
1003- with_coupon: false ,
1004- outputs: vec![ arm. var_ids[ 0 ] ] ,
1005- location: info. location,
1006- } ) ,
1007- ] ,
1008- BlockEnd :: Goto ( arm. block_id , Default :: default ( ) ) ,
1019+ vec ! [ ] ,
1020+ BlockEnd :: Goto ( info. arms [ 1 ] . block_id , Default :: default ( ) ) ,
10091021 ) ) ;
10101022 }
1011- } else {
1012- return Some ( (
1013- vec ! [ ] ,
1014- BlockEnd :: Goto ( info. arms [ 1 ] . block_id , Default :: default ( ) ) ,
1015- ) ) ;
1023+ Some ( None ) => { }
10161024 }
10171025 }
10181026 }
0 commit comments