sys_core_fold: Generalize case optimization
sys_core_fold: Generalize case optimization

For a long time, there has been an optimization for:

  {V1,V2,...} = case Expr of Pat -> ... {Val1,Val2,...}; ... end

that avoids building the tuples. The construct looks like this
in Core Erlang:

  let <V> = case X of
              Pattern -> {Y,Z}
            end
    in case V of
        {A,B} -> A+B
       end

The current optimization will try to replace the second 'case'
with a 'let':

  let <A,B> = case X of
                  Pattern -> <Y,Z>
                end
    in A+B

Simple variations of the construct would prevent the optimizations;
for example this one:

  let <V> = case X of
              Pattern -> {'ok',Val}
            end
    in case V of
        {ok,Val} -> Val
       end

The problem is that the optimization tries to do too much. By
making the optimization do less and have it depend on other
optimizations to finish the job, it will become more powerful.

Thus we can rewrite the code like this:

  let <V1,V2> = case X of
              Pattern -> <'ok',Val>
            end
    in let <V> = {V1,V2}
       in case V of
          {ok,Val} -> Val
       end

Note that the second case is unchanged. The other optimizations in the
sys_core_fold module will optimize the second 'case' and eliminate the
building of the tuple.

kvakvs/otp,johanclaesson/otp,haguenau/otp,goertzenator/otp,riverrun/otp,electricimp/otp,jinshana/otp,neeraj9/otp,fenollp/otp,yangchengjian/otp,stolen/otp,paladim/otp,krishnakumar4a4/otp,erlang/otp,aboroska/otp,RJ/otp,enikki/otp,RaimoNiskanen/otp,aboroska/otp,mikpe/otp,vinoski/otp,cnbin/otp,ferd/otp,sdebnath/otp,klarna/otp,GinjaNinja32/otp,legoscia/otp,paladim/otp,erlang/otp,Teino1978-Corp/otp,krishnakumar4a4/otp,dgud/otp,Teino1978-Corp/erlang-otp,stolen/otp,ahmedshafeeq/otp,bernardd/otp,jj1bdx/otp,saleyn/otp,bernardd/otp,falkevik/otp,RaimoNiskanen/otp,lucafavatella/otp,jemsbhai/otp,ferd/otp,massemanet/otp,lucafavatella/otp,RichMorin/otp,sdebnath/otp,johanclaesson/otp,benoitc/otp-1,mujiatong/otp,jemsbhai/otp,bsmr-erlang/otp,ferd/otp,aboroska/otp,paulcager/otp,lrascao/otp,aboroska/otp,matwey/otp,RGafiyatullin/otp,RaimoNiskanen/otp,enikki/otp,awetzel/otp,lemenkov/otp,sitexa/otp,massemanet/otp,emile/otp,sdebnath/otp,RichMorin/otp,isvilen/otp,c-rack/otp,lianghaivv/otp,bjorng/otp,tuncer/otp,mujiatong/otp,vinoski/otp,NOMORECOFFEE/otp,tuncer/otp,getong/otp,Teino1978-Corp/erlang-otp,goertzenator/otp,c-rack/otp,electricimp/otp,hairyhum/otp,cobusc/otp,jj1bdx/otp,uabboli/otp,GinjaNinja32/otp,GinjaNinja32/otp,erlang/otp,potatosalad/otp,krishnakumar4a4/otp,psyeugenic/otp,falkevik/otp,bugs-erlang-org/otp,hairyhum/otp,yangchengjian/otp,RoadRunnr/otp,weisslj/otp,schlagert/otp,yangchengjian/otp,haguenau/otp,cnbin/otp,RaimoNiskanen/otp,getong/otp,emile/otp,erlang/otp,yangchengjian/otp,beni55/otp,VincentHHL/otp,mikpe/otp,bjorng/otp,marquisthunder/otp,dumbbell/otp,RichMorin/otp,g-andrade/otp,getong/otp,klarna/otp,emile/otp,sdebnath/otp,emacsmirror/erlang,isvilen/otp,johanclaesson/otp,hairyhum/otp,ader1990/otp,sdebnath/otp,sitexa/otp,mikpe/otp,lightcyphers/otp,ahmedshafeeq/otp,kvakvs/otp,bjorng/otp,vinoski/otp,tuncer/otp,RichMorin/otp,entropiae/otp,haguenau/otp,gjaldon/otp,aboroska/otp,vinoski/otp,jinshana/otp,potatosalad/otp,awetzel/otp,msantos/otp,dumbbell/otp,dgud/otp,Teino1978-Corp/erlang-otp,uabboli/otp,bsmr-erlang/otp,lrascao/otp,jemsbhai/otp,paulcager/otp,yangchengjian/otp,jinshana/otp,emile/otp,lhslll/otp,johanclaesson/otp,sitexa/otp,mikpe/otp,bugs-erlang-org/otp,getong/otp,ahmedshafeeq/otp,entropiae/otp,goertzenator/otp,getong/otp,jamesruan/otp,johanclaesson/otp,vic/otp,haguenau/otp,RaimoNiskanen/otp,legoscia/otp,rlipscombe/otp,erlang/otp,mujiatong/otp,release-project/otp,bjorng/otp,enikki/otp,entropiae/otp,ferd/otp,vic/otp,lucafavatella/otp,g-andrade/otp,lianghaivv/otp,g-andrade/otp,jemsbhai/otp,RGafiyatullin/otp,psyeugenic/otp,enikki/otp,release-project/otp,krishnakumar4a4/otp,basho/otp,neeraj9/otp,mikpe/otp,potatosalad/otp,RJ/otp,stolen/otp,GinjaNinja32/otp,electricimp/otp,jj1bdx/otp,paladim/otp,emacsmirror/erlang,neeraj9/otp,goertzenator/otp,entropiae/otp,yangchengjian/otp,mikpe/otp,palas/otp,cobusc/otp,c-rack/otp,ader1990/otp,bugs-erlang-org/otp,sitexa/otp,vladdu/otp,NOMORECOFFEE/otp,stolen/otp,theom/otp,RoadRunnr/otp,jemsbhai/otp,basho/otp,bernardd/otp,RaimoNiskanen/otp,saleyn/otp,gjaldon/otp,isvilen/otp,lemenkov/otp,lemenkov/otp,palas/otp,lianghaivv/otp,bugs-erlang-org/otp,jamesruan/otp,awetzel/otp,jj1bdx/otp,riverrun/otp,lucafavatella/otp,cnbin/otp,massemanet/otp,mujiatong/otp,lemenkov/otp,matwey/otp,basho/otp,mikpe/otp,RGafiyatullin/otp,gjaldon/otp,fenollp/otp,vinoski/otp,lightcyphers/otp,derek121/otp,lemenkov/otp,marquisthunder/otp,jamesruan/otp,lightcyphers/otp,rlipscombe/otp,lhslll/otp,tuncer/otp,lemenkov/otp,VincentHHL/otp,bernardd/otp,lucafavatella/otp,release-project/otp,beni55/otp,mujiatong/otp,lantti/otp,saleyn/otp,Teino1978-Corp/otp,vinoski/otp,ferd/otp,ferd/otp,lemenkov/otp,matwey/otp,ader1990/otp,psyeugenic/otp,aboroska/otp,g-andrade/otp,potatosalad/otp,cnbin/otp,sammoth-wazoku/otp,lrascao/otp,cnbin/otp,benoitc/otp-1,paladim/otp,lantti/otp,psyeugenic/otp,bjorng/otp,cobusc/otp,massemanet/otp,RoadRunnr/otp,lhslll/otp,RGafiyatullin/otp,lhslll/otp,platinumthinker/otp,klarna/otp,neeraj9/otp,goertzenator/otp,palas/otp,bsmr-erlang/otp,RichMorin/otp,release-project/otp,g-andrade/otp,Teino1978-Corp/otp,massemanet/otp,benoitc/otp-1,ahmedshafeeq/otp,bsmr-erlang/otp,dumbbell/otp,erlang/otp,legoscia/otp,enikki/otp,paladim/otp,c-rack/otp,palas/otp,lightcyphers/otp,VincentHHL/otp,derek121/otp,uabboli/otp,bjorng/otp,msantos/otp,krishnakumar4a4/otp,awetzel/otp,marquisthunder/otp,GinjaNinja32/otp,RoadRunnr/otp,electricimp/otp,saleyn/otp,paladim/otp,weisslj/otp,potatosalad/otp,uabboli/otp,isvilen/otp,cobusc/otp,GinjaNinja32/otp,ahmedshafeeq/otp,tuncer/otp,erlang/otp,vinoski/otp,jinshana/otp,lhslll/otp,dgud/otp,uabboli/otp,schlagert/otp,ferd/otp,g-andrade/otp,gjaldon/otp,enikki/otp,msantos/otp,enikki/otp,sammoth-wazoku/otp,c-rack/otp,vic/otp,paulcager/otp,entropiae/otp,weisslj/otp,jinshana/otp,tuncer/otp,VincentHHL/otp,goertzenator/otp,jamesruan/otp,massemanet/otp,derek121/otp,yangchengjian/otp,bernardd/otp,dgud/otp,vladdu/otp,sammoth-wazoku/otp,theom/otp,paulcager/otp,dgud/otp,yangchengjian/otp,falkevik/otp,neeraj9/otp,emacsmirror/erlang,massemanet/otp,kvakvs/otp,schlagert/otp,lrascao/otp,emacsmirror/erlang,bsmr-erlang/otp,derek121/otp,RJ/otp,lianghaivv/otp,krishnakumar4a4/otp,sammoth-wazoku/otp,RoadRunnr/otp,release-project/otp,schlagert/otp,gjaldon/otp,theom/otp,Teino1978-Corp/erlang-otp,derek121/otp,rlipscombe/otp,lrascao/otp,psyeugenic/otp,RGafiyatullin/otp,paulcager/otp,paladim/otp,neeraj9/otp,klarna/otp,vic/otp,bernardd/otp,beni55/otp,RoadRunnr/otp,rlipscombe/otp,platinumthinker/otp,sitexa/otp,uabboli/otp,RichMorin/otp,aboroska/otp,RaimoNiskanen/otp,bernardd/otp,c-rack/otp,cobusc/otp,hairyhum/otp,psyeugenic/otp,beni55/otp,msantos/otp,getong/otp,VincentHHL/otp,NOMORECOFFEE/otp,ahmedshafeeq/otp,benoitc/otp-1,jinshana/otp,sammoth-wazoku/otp,ader1990/otp,bugs-erlang-org/otp,dgud/otp,riverrun/otp,dumbbell/otp,jemsbhai/otp,bsmr-erlang/otp,release-project/otp,theom/otp,release-project/otp,falkevik/otp,RJ/otp,sammoth-wazoku/otp,Teino1978-Corp/otp,electricimp/otp,NOMORECOFFEE/otp,isvilen/otp,basho/otp,RJ/otp,jinshana/otp,kvakvs/otp,theom/otp,ahmedshafeeq/otp,mikpe/otp,aboroska/otp,g-andrade/otp,fenollp/otp,RGafiyatullin/otp,basho/otp,hairyhum/otp,RoadRunnr/otp,sdebnath/otp,tuncer/otp,beni55/otp,stolen/otp,jemsbhai/otp,tuncer/otp,platinumthinker/otp,Teino1978-Corp/otp,jj1bdx/otp,falkevik/otp,falkevik/otp,lianghaivv/otp,klarna/otp,platinumthinker/otp,vinoski/otp,psyeugenic/otp,getong/otp,NOMORECOFFEE/otp,enikki/otp,Teino1978-Corp/erlang-otp,massemanet/otp,electricimp/otp,dgud/otp,RaimoNiskanen/otp,derek121/otp,emacsmirror/erlang,lucafavatella/otp,falkevik/otp,mujiatong/otp,jinshana/otp,lrascao/otp,lantti/otp,haguenau/otp,NOMORECOFFEE/otp,klarna/otp,ader1990/otp,RGafiyatullin/otp,bsmr-erlang/otp,fenollp/otp,isvilen/otp,jj1bdx/otp,kvakvs/otp,dumbbell/otp,riverrun/otp,cobusc/otp,ader1990/otp,lantti/otp,weisslj/otp,GinjaNinja32/otp,potatosalad/otp,goertzenator/otp,marquisthunder/otp,matwey/otp,ahmedshafeeq/otp,palas/otp,saleyn/otp,dumbbell/otp,sdebnath/otp,vic/otp,schlagert/otp,hairyhum/otp,sitexa/otp,weisslj/otp,dgud/otp,vic/otp,kvakvs/otp,fenollp/otp,rlipscombe/otp,schlagert/otp,vinoski/otp,potatosalad/otp,psyeugenic/otp,lantti/otp,mikpe/otp,awetzel/otp,ader1990/otp,basho/otp,bernardd/otp,paulcager/otp,uabboli/otp,mujiatong/otp,getong/otp,lantti/otp,ahmedshafeeq/otp,palas/otp,cnbin/otp,falkevik/otp,dumbbell/otp,RJ/otp,marquisthunder/otp,lrascao/otp,electricimp/otp,RoadRunnr/otp,klarna/otp,ferd/otp,falkevik/otp,jj1bdx/otp,RichMorin/otp,rlipscombe/otp,benoitc/otp-1,klarna/otp,saleyn/otp,isvilen/otp,jj1bdx/otp,jj1bdx/otp,entropiae/otp,legoscia/otp,beni55/otp,bugs-erlang-org/otp,dgud/otp,legoscia/otp,vladdu/otp,emacsmirror/erlang,emile/otp,bernardd/otp,weisslj/otp,legoscia/otp,lightcyphers/otp,massemanet/otp,theom/otp,kvakvs/otp,lightcyphers/otp,sdebnath/otp,isvilen/otp,vladdu/otp,johanclaesson/otp,bjorng/otp,bugs-erlang-org/otp,weisslj/otp,paulcager/otp,rlipscombe/otp,awetzel/otp,tuncer/otp,lucafavatella/otp,marquisthunder/otp,sammoth-wazoku/otp,aboroska/otp,schlagert/otp,beni55/otp,benoitc/otp-1,lrascao/otp,lantti/otp,Teino1978-Corp/otp,stolen/otp,theom/otp,stolen/otp,rlipscombe/otp,awetzel/otp,matwey/otp,Teino1978-Corp/erlang-otp,basho/otp,potatosalad/otp,cnbin/otp,sammoth-wazoku/otp,marquisthunder/otp,lrascao/otp,RJ/otp,bugs-erlang-org/otp,rlipscombe/otp,jamesruan/otp,uabboli/otp,weisslj/otp,entropiae/otp,lantti/otp,vladdu/otp,vic/otp,cobusc/otp,paladim/otp,isvilen/otp,c-rack/otp,vinoski/otp,NOMORECOFFEE/otp,lianghaivv/otp,derek121/otp,vladdu/otp,gjaldon/otp,potatosalad/otp,goertzenator/otp,neeraj9/otp,stolen/otp,RGafiyatullin/otp,RichMorin/otp,vladdu/otp,legoscia/otp,derek121/otp,g-andrade/otp,erlang/otp,erlang/otp,fenollp/otp,msantos/otp,jamesruan/otp,platinumthinker/otp,getong/otp,Teino1978-Corp/erlang-otp,gjaldon/otp,dumbbell/otp,emile/otp,lianghaivv/otp,kvakvs/otp,riverrun/otp,beni55/otp,matwey/otp,rlipscombe/otp,msantos/otp,hairyhum/otp,emacsmirror/erlang,jj1bdx/otp,saleyn/otp,sitexa/otp,lhslll/otp,Teino1978-Corp/otp,sitexa/otp,lhslll/otp,electricimp/otp,weisslj/otp,kvakvs/otp,dgud/otp,legoscia/otp,c-rack/otp,lightcyphers/otp,paulcager/otp,Teino1978-Corp/erlang-otp,basho/otp,Teino1978-Corp/otp,emacsmirror/erlang,gjaldon/otp,RaimoNiskanen/otp,fenollp/otp,vladdu/otp,potatosalad/otp,cnbin/otp,neeraj9/otp,msantos/otp,emile/otp,jamesruan/otp,NOMORECOFFEE/otp,palas/otp,riverrun/otp,electricimp/otp,isvilen/otp,riverrun/otp,emacsmirror/erlang,bjorng/otp,release-project/otp,vic/otp,theom/otp,emile/otp,johanclaesson/otp,GinjaNinja32/otp,emacsmirror/erlang,emile/otp,lemenkov/otp,platinumthinker/otp,matwey/otp,vladdu/otp,goertzenator/otp,platinumthinker/otp,fenollp/otp,matwey/otp,g-andrade/otp,cobusc/otp,legoscia/otp,RoadRunnr/otp,lianghaivv/otp,g-andrade/otp,bjorng/otp,marquisthunder/otp,palas/otp,johanclaesson/otp,jamesruan/otp,fenollp/otp,entropiae/otp,haguenau/otp,RJ/otp,ferd/otp,mikpe/otp,ader1990/otp,schlagert/otp,saleyn/otp,basho/otp,awetzel/otp,msantos/otp,matwey/otp,hairyhum/otp,bsmr-erlang/otp,lucafavatella/otp,lightcyphers/otp,dumbbell/otp,haguenau/otp,benoitc/otp-1,bsmr-erlang/otp,saleyn/otp,dumbbell/otp,krishnakumar4a4/otp,erlang/otp,krishnakumar4a4/otp,release-project/otp,haguenau/otp,lhslll/otp,mujiatong/otp,VincentHHL/otp,platinumthinker/otp,getong/otp,bjorng/otp,jemsbhai/otp,uabboli/otp,riverrun/otp,benoitc/otp-1,VincentHHL/otp,VincentHHL/otp