module Gibbon.L2.Examples
  ( -- * Data definitions
    ddtree, stree, ddexpr, ddsnoclist

    -- * Functions
  , add1Fun, add1TraversedFun, id1Fun, copyTreeFun, id2Fun, id3Fun, intAddFun
  , leftmostFun, buildLeafFun, testProdFun

    -- * Programs
  , add1Prog, id1Prog, copyTreeProg, id2Prog, copyOnId1Prog, id3Prog, intAddProg
  , leftmostProg, buildLeafProg, testProdProg, nodeProg, leafProg, testFlattenProg
  , rightmostProg, buildTreeProg, buildTreeSumProg, printTupProg, addTreesProg
  , printTupProg2, buildSTreeProg, sumUpProg, setEvenProg, sumUpSetEvenProg, substProg
  , buildTwoTreesProg, sumTreeProg, sumSTreeProg, indrRightmostProg, indrBuildTreeProg
  , indrIDProg, indrIDSumProg
  ) where

import Data.Set as S
import Data.Map as M

import Gibbon.Common
import Gibbon.L2.Syntax

--------------------------------------------------------------------------------

ddtree :: DDefs Ty2
ddtree :: DDefs Ty2
ddtree = [DDef Ty2] -> DDefs Ty2
forall a. [DDef a] -> DDefs a
fromListDD [LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, Ty2)])] -> DDef Ty2
forall a.
LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, a)])] -> DDef a
DDef (DataCon -> LocVar
toVar DataCon
"Tree") []
                      [ (DataCon
"Leaf",[(IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy)])
                      , (DataCon
"Node",[ (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l")
                                , (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l")])
                      ]]


tTypeable :: Exp2
tTypeable :: Exp2
tTypeable =  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r500") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
             E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l501" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r500")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
             (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v502",[], Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
42) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
             (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v502")

testTypeable :: UrTy LocVar
testTypeable :: Ty2
testTypeable = DDefs (TyOf Exp2) -> Env2 (TyOf Exp2) -> Exp2 -> TyOf Exp2
forall e.
Typeable e =>
DDefs (TyOf e) -> Env2 (TyOf e) -> e -> TyOf e
gRecoverType DDefs (TyOf Exp2)
DDefs Ty2
ddtree Env2 (TyOf Exp2)
Env2 Ty2
forall a. Env2 a
emptyEnv2 Exp2
tTypeable

--------------------------------------------------------------------------------
-- Add1

add1TraversedFun :: FunDef2
add1TraversedFun :: FunDef2
add1TraversedFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"add1" [LocVar
"tr1"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
add1TraversedFunTy Exp2
add1FunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where add1TraversedFunTy :: ArrowTy2 Ty2
add1TraversedFunTy = ArrowTy2 Ty2
add1FunTy { arrEffs :: Set Effect
arrEffs = [Effect] -> Set Effect
forall a. Ord a => [a] -> Set a
S.fromList [LocVar -> Effect
Traverse LocVar
"lin2"] }


add1Fun :: FunDef2
add1Fun :: FunDef2
add1Fun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"add1" [LocVar
"tr1"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
add1FunTy Exp2
add1FunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)


add1FunTy :: ArrowTy2 Ty2
add1FunTy :: ArrowTy2 Ty2
add1FunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
             [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin2" (LocVar -> Region
VarR LocVar
"r3") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout4" (LocVar -> Region
VarR LocVar
"r750") Modality
Output]
             [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin2"]
             Set Effect
forall a. Set a
S.empty
             (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout4")
             []
             IsBoxed
False


add1FunBod :: Exp2
add1FunBod :: Exp2
add1FunBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr1")
  [ (DataCon
"Leaf", [(LocVar
"n5",LocVar
"l6")],
      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v7",[],Ty2
forall loc. UrTy loc
IntTy,
               Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n5", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"lf8",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout4",
               LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout4" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v7"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
      LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"lf8")

  , (DataCon
"Node", [(LocVar
"x9",LocVar
"l10"),(LocVar
"y11",LocVar
"l12")],
     E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l13" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout4") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
     (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x14",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l13",
               LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"add1" [LocVar
"l10",LocVar
"l13"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x9"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
     E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l15" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x14" LocVar
"l13" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
     (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y16",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l15", LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"add1" [LocVar
"l12",LocVar
"l15"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y11"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
     (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z17",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout4",
              LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout4" DataCon
"Node" [ LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x14" , LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y16"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
     LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z17")
  ]

add1MainExp :: Exp2
add1MainExp :: Exp2
add1MainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r99") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l100" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r99")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l101" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l100") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x102",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l101",
                      LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l101" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
              E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l103" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x102" LocVar
"l101" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y104",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l103",
                      LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l103" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
              (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z105",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l100",
                      LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l100" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x102",
                                                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y104"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
              E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r106") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l107" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r106")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a108",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l107",
                      LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"add1" [LocVar
"l100", LocVar
"l107"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z105"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
              LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a108"


add1Prog :: Prog2
add1Prog :: Prog2
add1Prog = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"add1", FunDef2
add1Fun)])
           ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
add1MainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l107"))

--------------------------------------------------------------------------------

leafMainExp :: Exp2
leafMainExp :: Exp2
leafMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r150") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l151" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r150")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
              (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x152",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l151",
                       LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l151" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
              LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x152"

leafProg :: Prog2
leafProg :: Prog2
leafProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree FunDefs Exp2
forall k a. Map k a
M.empty ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
leafMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l151"))


--------------------------------------------------------------------------------

-- writes node
nodeMainExp :: Exp2
nodeMainExp :: Exp2
nodeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r155") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l156" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r155")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l157" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l156") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x158",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l157",
                       LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l157" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l159" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x158" LocVar
"l157" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y160",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l159",
                       LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l159" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z161",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l156",
                       LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l156" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x158", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y160"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z161"


nodeProg :: Prog2
nodeProg :: Prog2
nodeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree FunDefs Exp2
forall k a. Map k a
M.empty ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
nodeMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l156"))

--------------------------------------------------------------------------------

id1Fun :: FunDef2
id1Fun :: FunDef2
id1Fun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"id1" [LocVar
"tr18"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
idFunTy Exp2
forall {ext :: * -> * -> *} {loc} {dec}. PreExp ext loc dec
idFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    idFunBod :: PreExp ext loc dec
idFunBod = LocVar -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr18"

    idFunTy :: ArrowTy2 Ty2
    idFunTy :: ArrowTy2 Ty2
idFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
               [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin19" (LocVar -> Region
VarR LocVar
"r20") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout21" (LocVar -> Region
VarR LocVar
"r751") Modality
Output]
               [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin19"]
               (Set Effect
forall a. Set a
S.empty)
               (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout21")
               []
               IsBoxed
False


id1Prog :: Prog2
id1Prog :: Prog2
id1Prog = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"id1", FunDef2
id1Fun)]) Maybe (Exp2, TyOf Exp2)
Maybe (Exp2, Ty2)
forall a. Maybe a
Nothing

--------------------------------------------------------------------------------

copyTreeFun :: FunDef2
copyTreeFun :: FunDef2
copyTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"copyTree" [LocVar
"tr22"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
copyFunTy Exp2
copyBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    copyFunTy :: ArrowTy2 Ty2
copyFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                 [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin23" (LocVar -> Region
VarR LocVar
"r24") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout25" (LocVar -> Region
VarR LocVar
"r752") Modality
Output]
                 [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin23"]
                 Set Effect
forall a. Set a
S.empty
                 (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout25")
                 []
                 IsBoxed
False

    copyBod :: Exp2
copyBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr22")
                 [ (DataCon
"Leaf", [(LocVar
"n27",LocVar
"lin26")],
                     (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"n28",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout25",
                               LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout25" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n27"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                     LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n28")

                 , (DataCon
"Node", [(LocVar
"x29",LocVar
"lx30"),(LocVar
"y31",LocVar
"ly32")],
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext  (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"lx33" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout25") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x34", [], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lx33",
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyTree" [LocVar
"lx30",LocVar
"lx33"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x29"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext  (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"ly35" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x34" LocVar
"lx33" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y36", [], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"ly35",
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyTree" [LocVar
"ly32",LocVar
"ly35"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y31"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout25" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x34", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y36"])
                 ]

copyTreeMainExp :: Exp2
copyTreeMainExp :: Exp2
copyTreeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r200") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l201" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r200")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l202" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l201") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x203",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l202",
                          LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l202" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"r204" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x203" LocVar
"l202" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y205",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"r204",
                           LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"r204" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z206",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l201",
                           LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l201" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x203", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y205"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r207") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l208" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r207")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a209",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l208",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyTree" [LocVar
"l201", LocVar
"l208"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z206"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a209"

copyTreeProg :: Prog2
copyTreeProg :: Prog2
copyTreeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"copyTree", FunDef2
copyTreeFun)]) (Maybe (Exp2, TyOf Exp2) -> Prog2)
-> Maybe (Exp2, TyOf Exp2) -> Prog2
forall a b. (a -> b) -> a -> b
$
               (Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
copyTreeMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l208")

--------------------------------------------------------------------------------

id2Fun :: FunDef2
id2Fun :: FunDef2
id2Fun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"id2" [LocVar
"tr41"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
id2Ty Exp2
forall {ext :: * -> * -> *} {loc} {dec}. PreExp ext loc dec
id2Bod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    id2Ty :: ArrowTy2 Ty2
    id2Ty :: ArrowTy2 Ty2
id2Ty = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
             [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin37" (LocVar -> Region
VarR LocVar
"r38") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout39" (LocVar -> Region
VarR LocVar
"r753") Modality
Output]
             [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin37"]
             (Set Effect
forall a. Set a
S.empty)
             (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout39")
             []
             IsBoxed
False

    id2Bod :: PreExp ext loc dec
id2Bod = PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim dec
forall ty. Prim ty
EqIntP [Int -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
20, Int -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
20])
             (LocVar -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr41")
             (LocVar -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr41")

id2Prog :: Prog2
id2Prog :: Prog2
id2Prog = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"id2", FunDef2
id2Fun)]) Maybe (Exp2, TyOf Exp2)
Maybe (Exp2, Ty2)
forall a. Maybe a
Nothing

--------------------------------------------------------------------------------

copyOnId1Prog :: Prog2
copyOnId1Prog :: Prog2
copyOnId1Prog = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree FunDefs Exp2
funs (Maybe (Exp2, TyOf Exp2) -> Prog2)
-> Maybe (Exp2, TyOf Exp2) -> Prog2
forall a b. (a -> b) -> a -> b
$ (Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
copyOnId1MainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l228")
  where
    funs :: FunDefs Exp2
funs  = [(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"copyTree" , FunDef2
copyTreeFun),
                         (LocVar
"id1WithCopy", FunDef2
id1WithCopyFun)]

copyOnId1MainExp :: Exp2
copyOnId1MainExp :: Exp2
copyOnId1MainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r220") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l221" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r220")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l222" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l221") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"l223",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l222",
                           LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l222" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l224" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"l223" LocVar
"l222" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"l225",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l224",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l224" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z226",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l221",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l221" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"l223", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"l225"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r227") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l228" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r227")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a229",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l228",
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"id1WithCopy" [LocVar
"l221", LocVar
"l228"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z226"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a229"

id1WithCopyFun :: FunDef2
id1WithCopyFun :: FunDef2
id1WithCopyFun = FunDef2
id1Fun { funBody :: Exp2
funBody = LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyTree" [LocVar
"lin19",LocVar
"lout21"]
                                    [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr18"]
                        , funName :: LocVar
funName = LocVar
"id1WithCopy"
                        }

--------------------------------------------------------------------------------

id3Fun :: FunDef2
id3Fun :: FunDef2
id3Fun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"id3" [LocVar
"i42"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
id3Ty Exp2
forall {ext :: * -> * -> *} {loc} {dec}. PreExp ext loc dec
id3Bod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    id3Ty :: ArrowTy2 Ty2
    id3Ty :: ArrowTy2 Ty2
id3Ty = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
             []
             [Ty2
forall loc. UrTy loc
IntTy]
             (Set Effect
forall a. Set a
S.empty)
             (Ty2
forall loc. UrTy loc
IntTy)
             []
             IsBoxed
False
    id3Bod :: PreExp ext loc dec
id3Bod = LocVar -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i42"

id3MainExp :: Exp2
id3MainExp :: Exp2
id3MainExp = LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"id3" [] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
42]

id3Prog :: Prog2
id3Prog :: Prog2
id3Prog = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"id3", FunDef2
id3Fun)]) (Maybe (Exp2, TyOf Exp2) -> Prog2)
-> Maybe (Exp2, TyOf Exp2) -> Prog2
forall a b. (a -> b) -> a -> b
$ (Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
id3MainExp, Ty2
forall loc. UrTy loc
IntTy)


--------------------------------------------------------------------------------

intAddFun :: FunDef2
intAddFun :: FunDef2
intAddFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"intAdd" [LocVar
"i109"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
intAddTy Exp2
forall {ext :: * -> * -> *} {loc} {dec}. PreExp ext loc dec
id3Bod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    intAddTy :: ArrowTy2 Ty2
    intAddTy :: ArrowTy2 Ty2
intAddTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                []
                [[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, Ty2
forall loc. UrTy loc
IntTy]]
                (Set Effect
forall a. Set a
S.empty)
                (Ty2
forall loc. UrTy loc
IntTy)
                []
                IsBoxed
False
    id3Bod :: PreExp ext loc dec
id3Bod = Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim dec
forall ty. Prim ty
AddP [Int -> PreExp ext loc dec -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i109"), Int -> PreExp ext loc dec -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> PreExp ext loc dec
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i109")]

intAddMainExp :: Exp2
intAddMainExp :: Exp2
intAddMainExp = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sum110", [], Ty2
forall loc. UrTy loc
IntTy,
                         LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"intAdd" []
                         [[Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
40,Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]])
                (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sum110")

intAddProg :: Prog2
intAddProg :: Prog2
intAddProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
forall k a. Map k a
M.empty ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"intAdd", FunDef2
intAddFun)]) ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
intAddMainExp, Ty2
forall loc. UrTy loc
IntTy))

--------------------------------------------------------------------------------

leftmostFun :: FunDef2
leftmostFun :: FunDef2
leftmostFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"leftmost" [LocVar
"t111"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
leftmostTy Exp2
leftmostBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    leftmostTy :: ArrowTy2 Ty2
    leftmostTy :: ArrowTy2 Ty2
leftmostTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                 [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin112" (LocVar -> Region
VarR LocVar
"r113") Modality
Input]
                 [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin112"]
                 (Set Effect
forall a. Set a
S.empty)
                 (Ty2
forall loc. UrTy loc
IntTy)
                 []
                 IsBoxed
False

leftmostBod :: Exp2
leftmostBod :: Exp2
leftmostBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t111")
              [(DataCon
"Leaf", [(LocVar
"n114",LocVar
"l115")],
                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n114"),
               (DataCon
"Node", [(LocVar
"x117",LocVar
"l118"), (LocVar
"y119",LocVar
"l120")],
                (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"lm121",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"leftmost" [LocVar
"l118"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x117"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"lm121")]

leftmostMainExp :: Exp2
leftmostMainExp :: Exp2
leftmostMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r122") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l123" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r122")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l124" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l123") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x125",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l124",
                          LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l124" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l126" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x125" LocVar
"l124" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y128",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l126",
                          LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l126" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z127",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l123",
                          LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l123" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x125", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y128"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a131",[], Ty2
forall loc. UrTy loc
IntTy,
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"leftmost" [LocVar
"l123"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z127"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a131"

leftmostProg :: Prog2
leftmostProg :: Prog2
leftmostProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"leftmost", FunDef2
leftmostFun)]) ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
leftmostMainExp, Ty2
forall loc. UrTy loc
IntTy))


--------------------------------------------------------------------------------

rightmostFun :: FunDef2
rightmostFun :: FunDef2
rightmostFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"rightmost" [LocVar
"t242"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
rightmostTy Exp2
rightmostBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    rightmostTy :: ArrowTy2 Ty2
    rightmostTy :: ArrowTy2 Ty2
rightmostTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                   [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin241" (LocVar -> Region
VarR LocVar
"r240") Modality
Input]
                   [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin241"]
                   (Set Effect
forall a. Set a
S.empty)
                   (Ty2
forall loc. UrTy loc
IntTy)
                   []
                   IsBoxed
False

rightmostBod :: Exp2
rightmostBod :: Exp2
rightmostBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t242")
               [(DataCon
"Leaf", [(LocVar
"n246",LocVar
"l247")],
                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n246"),
                (DataCon
"Node", [(LocVar
"x248",LocVar
"l249"), (LocVar
"y250",LocVar
"l251")],
                 -- Ext $ LetRegionE (VarR "r252") Undefined Nothing $
                 -- Ext $ LetLocE "l253" (StartOfRegionLE (VarR "r252")) $
                 -- LetE ("x254",[],PackedTy "Tree" "l253",
                 --          AppE "copyTree" ["l249", "l253"] (VarE "x248")) $
                 LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"rightmost" [LocVar
"l251"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y250"]
                )]

rightmostMainExp :: Exp2
rightmostMainExp :: Exp2
rightmostMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r253") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l254" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r253")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l255" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l254") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x256",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l255",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l255" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l257" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x256" LocVar
"l255" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y258",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l257",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l257" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z259",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l254",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l254" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x256", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y258"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a260",[], Ty2
forall loc. UrTy loc
IntTy,
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"rightmost" [LocVar
"l254"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z259"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a260"

rightmostProg :: Prog2
rightmostProg :: Prog2
rightmostProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"rightmost", FunDef2
rightmostFun)])
                ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
rightmostMainExp, Ty2
forall loc. UrTy loc
IntTy))


--------------------------------------------------------------------------------

buildLeafFun :: FunDef2
buildLeafFun :: FunDef2
buildLeafFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"buildLeaf" [LocVar
"i125"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
buildLeafTy Exp2
buildLeafBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    buildLeafTy :: ArrowTy2 Ty2
    buildLeafTy :: ArrowTy2 Ty2
buildLeafTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                   [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout126" (LocVar -> Region
VarR LocVar
"r127") Modality
Output]
                   [Ty2
forall loc. UrTy loc
IntTy]
                   (Set Effect
forall a. Set a
S.empty)
                   (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout126")
                   []
                   IsBoxed
False

    buildLeafBod :: Exp2
    buildLeafBod :: Exp2
buildLeafBod = LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout126" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i125"]


buildLeafMainExp :: Exp2
buildLeafMainExp :: Exp2
buildLeafMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r128") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l129" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r128")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildLeaf" [LocVar
"l129"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
42]

buildLeafProg :: Prog2
buildLeafProg :: Prog2
buildLeafProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildLeaf", FunDef2
buildLeafFun)]) ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
buildLeafMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l129"))


--------------------------------------------------------------------------------

buildTreeFun :: FunDef2
buildTreeFun :: FunDef2
buildTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"buildTree" [LocVar
"i270"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
buildTreeTy Exp2
buildTreeBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    buildTreeTy :: ArrowTy2 Ty2
    buildTreeTy :: ArrowTy2 Ty2
buildTreeTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                   [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout272" (LocVar -> Region
VarR LocVar
"r271") Modality
Output]
                   [Ty2
forall loc. UrTy loc
IntTy]
                   (Set Effect
forall a. Set a
S.empty)
                   (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout272")
                   []
                   IsBoxed
False

    buildTreeBod :: Exp2
    buildTreeBod :: Exp2
buildTreeBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b279",[], Ty2
forall loc. UrTy loc
BoolTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i270", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   Exp2 -> Exp2 -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b279")
                   (LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout272" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1])
                   ((LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i273",[], Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
SubP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i270", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l274" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout272") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x275",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l274",
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l274"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i273"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l276" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x275" LocVar
"l274" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y277",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l276",
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l276"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i273"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a278",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout272",
                             LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout272" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x275", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y277"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a278")


buildTreeMainExp :: Exp2
buildTreeMainExp :: Exp2
buildTreeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r279") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l280" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r279")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l280"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]

buildTreeProg :: Prog2
buildTreeProg :: Prog2
buildTreeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildTree", FunDef2
buildTreeFun)]) ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
buildTreeMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l280"))


--------------------------------------------------------------------------------


buildTwoTreesFun :: FunDef2
buildTwoTreesFun :: FunDef2
buildTwoTreesFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"buildTwoTrees" [LocVar
"i750"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
buildTreeTy Exp2
buildTreeBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    buildTreeTy :: ArrowTy2 Ty2
    buildTreeTy :: ArrowTy2 Ty2
buildTreeTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                   [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout752" (LocVar -> Region
VarR LocVar
"r751") Modality
Output, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout754" (LocVar -> Region
VarR LocVar
"r753") Modality
Output]
                   [Ty2
forall loc. UrTy loc
IntTy]
                   (Set Effect
forall a. Set a
S.empty)
                   ([Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout752", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout754"])
                   []
                   IsBoxed
False

    buildTreeBod :: Exp2
    buildTreeBod :: Exp2
buildTreeBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tree1",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout752",
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"lout752"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i750"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tree2",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout754",
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"lout754"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i750"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a755",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout752", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout754"],
                            [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree1", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree2"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a755"

buildTwoTreesMainExp :: Exp2
buildTwoTreesMainExp :: Exp2
buildTwoTreesMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r756") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l757" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r756")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r758") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l759" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r758")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"treeprod", [], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout757", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout759"],
                                LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTwoTrees" [LocVar
"l757", LocVar
"l759"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"treeprod"

buildTwoTreesProg :: Prog2
buildTwoTreesProg :: Prog2
buildTwoTreesProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildTree", FunDef2
buildTreeFun),
                                             (LocVar
"buildTwoTrees", FunDef2
buildTwoTreesFun)])
                         ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
buildTwoTreesMainExp, [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout757", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout759"]))

--------------------------------------------------------------------------------

buildTreeSumFun :: FunDef2
buildTreeSumFun :: FunDef2
buildTreeSumFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"buildTreeSum" [LocVar
"i302"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
buildTreeSumTy Exp2
buildTreeSumBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    buildTreeSumTy :: ArrowTy2 Ty2
    buildTreeSumTy :: ArrowTy2 Ty2
buildTreeSumTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                      [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout301" (LocVar -> Region
VarR LocVar
"r300") Modality
Output]
                      [Ty2
forall loc. UrTy loc
IntTy]
                      (Set Effect
forall a. Set a
S.empty)
                      ([Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout301"])
                      []
                      IsBoxed
False

    buildTreeSumBod :: Exp2
    buildTreeSumBod :: Exp2
buildTreeSumBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b303",[], Ty2
forall loc. UrTy loc
BoolTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i302", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                      Exp2 -> Exp2 -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b303")
                      ((LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"c316",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout301",
                                LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout301" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"t317",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout301"],
                               [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1, LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"c316"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t317")
                      ((LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i303",[], Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
SubP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i302", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l304" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout301") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"t318",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l304"],
                                LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTreeSum" [LocVar
"l304"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i303"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i309",[],Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t318")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x305",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l304", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t318")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l306" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x305" LocVar
"l304" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"t319",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l306"],
                                LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTreeSum" [LocVar
"l306"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i303"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i310",[],Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t319")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y307",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l306", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t319")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"j311",[],Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i309", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i310"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a308",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout301",
                                LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout301" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x305", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y307"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b312",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout301"],
                                [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"j311", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a308"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b312")


buildTreeSumMainExp :: Exp2
buildTreeSumMainExp :: Exp2
buildTreeSumMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r313") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                      E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l314" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r313")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z315",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l314"],
                               LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTreeSum" [LocVar
"l314"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                      LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z315"


buildTreeSumProg :: Prog2
buildTreeSumProg :: Prog2
buildTreeSumProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildTreeSum", FunDef2
buildTreeSumFun)]) ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
buildTreeSumMainExp, [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l314"]))

--------------------------------------------------------------------------------

sumTreeFun :: FunDef2
sumTreeFun :: FunDef2
sumTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"sumTree" [LocVar
"tr762"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
sumTreeTy Exp2
sumTreeBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    sumTreeTy :: ArrowTy2 Ty2
    sumTreeTy :: ArrowTy2 Ty2
sumTreeTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                      [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin761" (LocVar -> Region
VarR LocVar
"r760") Modality
Input]
                      [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin761"]
                      (Set Effect
forall a. Set a
S.empty)
                      (Ty2
forall loc. UrTy loc
IntTy)
                      []
                      IsBoxed
False

    sumTreeBod :: Exp2
    sumTreeBod :: Exp2
sumTreeBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr762")
                 [ (DataCon
"Leaf", [(LocVar
"n763", LocVar
"l764")],
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n763")
                 , (DataCon
"Node", [(LocVar
"x764",LocVar
"l765"), (LocVar
"y766",LocVar
"l767")],
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sx768", [], Ty2
forall loc. UrTy loc
IntTy,
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumTree" [LocVar
"l765"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x764"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sy769", [], Ty2
forall loc. UrTy loc
IntTy,
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumTree" [LocVar
"l767"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y766"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"total770", [], Ty2
forall loc. UrTy loc
IntTy ,
                            Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sx768", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sy769"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"total770"
                   )]

sumTreeMainExp :: Exp2
sumTreeMainExp :: Exp2
sumTreeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r771") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l772" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r771")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr773", [], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l772",
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l772"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sum774", [], Ty2
forall loc. UrTy loc
IntTy,
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumTree" [LocVar
"l772"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr773"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sum774"

sumTreeProg :: Prog2
sumTreeProg :: Prog2
sumTreeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildTree", FunDef2
buildTreeFun),
                                       (LocVar
"sumTree", FunDef2
sumTreeFun)
                                      ])
                   ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
sumTreeMainExp, Ty2
forall loc. UrTy loc
IntTy))

--------------------------------------------------------------------------------

printTupMainExp :: Exp2
printTupMainExp :: Exp2
printTupMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r325") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l326" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r325")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i327",[], Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
42) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x328",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l326",
                           LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l326" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"t329",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l326"],
                           [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i327", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x328"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t329"

printTupProg :: Prog2
printTupProg :: Prog2
printTupProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree FunDefs Exp2
forall k a. Map k a
M.empty ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
printTupMainExp, [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l326"]))

--------------------------------------------------------------------------------

printTupMainExp2 :: Exp2
printTupMainExp2 :: Exp2
printTupMainExp2 = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r400") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l401" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r400")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x402",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l401",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l401"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l403" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x402" LocVar
"l401" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y404",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l403",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l403"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z405",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l401", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l403"],
                           [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x402", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y404"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z405"

printTupProg2 :: Prog2
printTupProg2 :: Prog2
printTupProg2 = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildTree", FunDef2
buildTreeFun)])
                ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
printTupMainExp2,
                       [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l401", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l403"]))

--------------------------------------------------------------------------------

{-

addTrees :: Tree -> Tree -> Tree
addTrees t1 t2 =
  case t1 of
    Leaf n1    -> case t2 of
                    Leaf n2 -> Leaf (n1 + n2)
                    Node l2 r2 -> error "expected leaf here"
    Node l1 r1 -> case t2 of
                    Leaf n2 -> error "expected node here"
                    Node l2 r2 -> Node (addTrees l1 l2) (addTrees r1 r2)
-}

addTreesFun :: FunDef2
addTreesFun :: FunDef2
addTreesFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"addTrees" [LocVar
"trees354"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
addTreesTy Exp2
addTreesBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    addTreesTy :: ArrowTy2 Ty2
    addTreesTy :: ArrowTy2 Ty2
addTreesTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                  [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin351" (LocVar -> Region
VarR LocVar
"r350") Modality
Input,
                   LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin352" (LocVar -> Region
VarR LocVar
"r351") Modality
Input,
                   LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout353" (LocVar -> Region
VarR LocVar
"r754") Modality
Output]
                  [[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin351", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin352"]]
                  (Set Effect
forall a. Set a
S.empty)
                  (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout353")
                  []
                  IsBoxed
False

    addTreesBod :: Exp2
    addTreesBod :: Exp2
addTreesBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tree1",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin351",
                           Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"trees354")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tree2",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin352",
                           Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"trees354")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree1")
                  [(DataCon
"Leaf", [(LocVar
"n355",LocVar
"l356")],
                    Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree2")
                       [(DataCon
"Leaf",[(LocVar
"n357",LocVar
"l358")],
                         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"n358",[],Ty2
forall loc. UrTy loc
IntTy,Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n355",LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n357"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x359",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout353",
                                  LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout353" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n358"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                         LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x359"
                        )]
                   ),
                    (DataCon
"Node", [(LocVar
"x360",LocVar
"l361"), (LocVar
"y362",LocVar
"l363")],
                     Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree2")
                        [(DataCon
"Node", [(LocVar
"x364",LocVar
"l365"), (LocVar
"y366",LocVar
"l367")],
                          E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l368" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout353") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tree3",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l361",
                                                      DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l365"],
                                   [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x360", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x364"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x369",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l368",
                                   LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"addTrees" [LocVar
"l361",LocVar
"l365",LocVar
"l368"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree3"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                          E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l370" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x369" LocVar
"l368" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tree4",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l363",
                                                      DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l367"],
                                   [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y362", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y366"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y371",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l370",
                                   LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"addTrees" [LocVar
"l363",LocVar
"l367",LocVar
"l370"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tree4"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z372",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout353",
                                    LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout353" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x369", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y371"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                          LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z372"
                         )]
                    )]

addTreesMainExp :: Exp2
addTreesMainExp :: Exp2
addTreesMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r400") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l401" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r400")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x402",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l401",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l401"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  -- Ext $ LetLocE "l403" (AfterVariableLE "x402" "l401" True) $
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r403") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l403" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r403")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y404",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l403",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l403"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z405",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l401", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l403"],
                           [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x402", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y404"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r405") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l406" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r405")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a407",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l406",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"addTrees" [LocVar
"l401",LocVar
"l403",LocVar
"l406"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z405"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a407"

addTreesProg :: Prog2
addTreesProg :: Prog2
addTreesProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"addTrees", FunDef2
addTreesFun)
                                       ,(LocVar
"buildTree", FunDef2
buildTreeFun)])
                    ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
addTreesMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l406"))

--------------------------------------------------------------------------------

testProdFun :: FunDef2
testProdFun :: FunDef2
testProdFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"testprod" [LocVar
"tup130"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
testprodTy Exp2
testprodBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    testprodTy :: ArrowTy2 Ty2
testprodTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                  [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin131" (LocVar -> Region
VarR LocVar
"r132") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout133" (LocVar -> Region
VarR LocVar
"r755") Modality
Output]
                  [[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [(DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin131"), Ty2
forall loc. UrTy loc
IntTy]]
                  (Set Effect
forall a. Set a
S.empty)
                  ([Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [(DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout133"), Ty2
forall loc. UrTy loc
IntTy])
                  []
                  IsBoxed
False
    testprodBod :: Exp2
testprodBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"t134",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin131", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tup130")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i135",[], Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tup130")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t134")
                  [(DataCon
"Leaf",[(LocVar
"n136",LocVar
"l137")],
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v138",[],Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n136", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"lf139",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout133",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout133" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v138"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tup148",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout133", Ty2
forall loc. UrTy loc
IntTy],
                       [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"lf139", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i135"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tup148"
                   ),
                   (DataCon
"Node",[(LocVar
"x140",LocVar
"l141"), (LocVar
"y142",LocVar
"l143")],
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l144" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout133") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tup145",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l144", Ty2
forall loc. UrTy loc
IntTy],
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"testprod" [LocVar
"l141",LocVar
"l144"]
                             [[Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x140", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i135"]]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$

                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x149",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l144", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tup145")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l146" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x149" LocVar
"l144" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tup147",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l146", Ty2
forall loc. UrTy loc
IntTy],
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"testprod" [LocVar
"l143",LocVar
"l146"]
                            [[Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y142", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i135"]]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y150",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l146", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tup147")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"node151",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout133",
                            LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout133" DataCon
"Node" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x149", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y150"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tup152",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout133", Ty2
forall loc. UrTy loc
IntTy],
                            [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"node151", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i135"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tup152")
                  ]

testProdProg :: Prog2
testProdProg :: Prog2
testProdProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"testprod", FunDef2
testProdFun)]) Maybe (Exp2, TyOf Exp2)
Maybe (Exp2, Ty2)
forall a. Maybe a
Nothing

--------------------------------------------------------------------------------

-- Meaningless program, just to test flattenL2
testFlattenProg :: Prog2
testFlattenProg :: Prog2
testFlattenProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
forall k a. Map k a
M.empty ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"intAdd",FunDef2
intAddFun)]) (Maybe (Exp2, TyOf Exp2) -> Prog2)
-> Maybe (Exp2, TyOf Exp2) -> Prog2
forall a b. (a -> b) -> a -> b
$ (Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
testFlattenBod, Ty2
forall loc. UrTy loc
IntTy)
  where
    testFlattenBod :: Exp2
    testFlattenBod :: Exp2
testFlattenBod =
      E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"_") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
      E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"_" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"_")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
      E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"_" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"_") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v170",[],Ty2
forall loc. UrTy loc
IntTy,
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v171",[],Ty2
forall loc. UrTy loc
IntTy,
                        LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"intAdd" []
                        [[Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
40, Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2],
                                     Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
SubP [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
44, Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]]]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v171") (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
      LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v170"

--------------------------------------------------------------------------------

-- sumUp + setEven example in L2
-- gensym starts at 500

stree :: DDefs Ty2
stree :: DDefs Ty2
stree = [DDef Ty2] -> DDefs Ty2
forall a. [DDef a] -> DDefs a
fromListDD [LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, Ty2)])] -> DDef Ty2
forall a.
LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, a)])] -> DDef a
DDef (DataCon -> LocVar
toVar DataCon
"STree") []
                    [ (DataCon
"Leaf",[(IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy)])
                    , (DataCon
"Inner",[ (IsBoxed
False, Ty2
forall loc. UrTy loc
IntTy)
                               , (IsBoxed
False, Ty2
forall loc. UrTy loc
IntTy) -- this should be a boolean.
                                                -- for now, 1 is true, 0 is false
                               , (IsBoxed
False, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l")
                               , (IsBoxed
False, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l")])
                    ]]

{-

sumUp :: Tree -> Tree
sumUp tree =
  case tree of
    Leaf x -> Leaf x
    Inner sum x l r ->
      let l'   = sum_up l
          r'   = sum_up r
          v1   = value l'
          v2   = value  r'
          sum' = v1 + v2
      in Inner sum' x l' r'

-}

sumUpFun :: FunDef2
sumUpFun :: FunDef2
sumUpFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"sumUp" [LocVar
"tr1"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
sumUpFunTy Exp2
sumUpFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    sumUpFunTy :: ArrowTy2 Ty2
    sumUpFunTy :: ArrowTy2 Ty2
sumUpFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                  [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin501" (LocVar -> Region
VarR LocVar
"r500") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout502" (LocVar -> Region
VarR LocVar
"r756") Modality
Output]
                  [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lin501"]
                  (Set Effect
forall a. Set a
S.empty)
                  (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout502")
                  []
                  IsBoxed
False


    sumUpFunBod :: Exp2
    sumUpFunBod :: Exp2
sumUpFunBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr1")
      [ (DataCon
"Leaf", [(LocVar
"n503",LocVar
"l504")],
          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x505",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout502",
                   LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout502" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n503"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
          LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x505")

      , (DataCon
"Inner", [(LocVar
"i506",LocVar
"l507"),(LocVar
"b508",LocVar
"l509"),(LocVar
"x510",LocVar
"l511"),(LocVar
"y512",LocVar
"l513")],
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l514" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout502") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l550" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"i506" LocVar
"l514" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l551" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"b508" LocVar
"l550" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x515",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l551",
                   LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumUp" [LocVar
"l511",LocVar
"l551"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x510"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l516" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x515" LocVar
"l551" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y517",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l516",
                  LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumUp" [LocVar
"l513",LocVar
"l516"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y512"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v518",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"valueSTree" [LocVar
"l551"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x515"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v519",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"valueSTree" [LocVar
"l516"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y517"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v520",[],Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v518", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v519"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z521",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout502",
                  LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout502" DataCon
"Inner" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v520", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b508",
                                                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x515", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y517"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z521"
        )]


valueSTreeFun :: FunDef2
valueSTreeFun :: FunDef2
valueSTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"valueSTree" [LocVar
"tr522"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
valueSTreeFunTy Exp2
valueSTreeFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    valueSTreeFunTy :: ArrowTy2 Ty2
    valueSTreeFunTy :: ArrowTy2 Ty2
valueSTreeFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                       [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin524" (LocVar -> Region
VarR LocVar
"r523") Modality
Input]
                       [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lin524"]
                       (Set Effect
forall a. Set a
S.empty)
                       (Ty2
forall loc. UrTy loc
IntTy)
                       []
                       IsBoxed
False

    valueSTreeFunBod :: Exp2
    valueSTreeFunBod :: Exp2
valueSTreeFunBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr522")
      [ (DataCon
"Leaf", [(LocVar
"n523",LocVar
"l524")],
          LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n523")

      , (DataCon
"Inner", [(LocVar
"i525",LocVar
"l526"),(LocVar
"b527",LocVar
"l528"),(LocVar
"x529",LocVar
"l530"),(LocVar
"y531",LocVar
"l532")],
         LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i525"
      )]


buildSTreeFun :: FunDef2
buildSTreeFun :: FunDef2
buildSTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"buildSTree" [LocVar
"i543"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
buildSTreeTy Exp2
buildSTreeBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    buildSTreeTy :: ArrowTy2 Ty2
    buildSTreeTy :: ArrowTy2 Ty2
buildSTreeTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                    [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout541" (LocVar -> Region
VarR LocVar
"r540") Modality
Output]
                    [Ty2
forall loc. UrTy loc
IntTy]
                    (Set Effect
forall a. Set a
S.empty)
                    (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout541")
                    []
                    IsBoxed
False

    buildSTreeBod :: Exp2
    buildSTreeBod :: Exp2
buildSTreeBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b542",[], Ty2
forall loc. UrTy loc
BoolTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i543", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   Exp2 -> Exp2 -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b542")
                   (LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout541" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1])
                   ((LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i548",[], Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
SubP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i543", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i554",[], Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b555",[], Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l544" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout541") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l552" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"i554" LocVar
"l544" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l553" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"b555" LocVar
"l552" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x545",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l553",
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l553"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i548"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l545" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x545" LocVar
"l553" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y546",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l545",
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l545"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i548"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a547",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout541",
                             LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout541" DataCon
"Inner" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i554", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b555",
                                                            LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x545", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y546"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a547")


buildSTreeMainExp :: Exp2
buildSTreeMainExp :: Exp2
buildSTreeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r530") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l531" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r530")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                    (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x532",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l531",
                             LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l531"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                    LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x532"


buildSTreeProg :: Prog2
buildSTreeProg :: Prog2
buildSTreeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
stree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildSTree", FunDef2
buildSTreeFun)])
                      ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
buildSTreeMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l531"))


--------------------------------------------------------------------------------

sumSTreeFun :: FunDef2
sumSTreeFun :: FunDef2
sumSTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"sumSTree" [LocVar
"tr762"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
sumSTreeTy Exp2
sumSTreeBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    sumSTreeTy :: ArrowTy2 Ty2
    sumSTreeTy :: ArrowTy2 Ty2
sumSTreeTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                      [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin761" (LocVar -> Region
VarR LocVar
"r760") Modality
Input]
                      [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lin761"]
                      (Set Effect
forall a. Set a
S.empty)
                      (Ty2
forall loc. UrTy loc
IntTy)
                      []
                      IsBoxed
False

    sumSTreeBod :: Exp2
    sumSTreeBod :: Exp2
sumSTreeBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr762")
                 [ (DataCon
"Leaf", [(LocVar
"n763", LocVar
"l764")],
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n763")
                 , (DataCon
"Inner", [(LocVar
"i775",LocVar
"l776"),(LocVar
"b777",LocVar
"l778"),
                              (LocVar
"x764",LocVar
"l765"), (LocVar
"y766",LocVar
"l767")],
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sx768", [], Ty2
forall loc. UrTy loc
IntTy,
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumSTree" [LocVar
"l765"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x764"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sy769", [], Ty2
forall loc. UrTy loc
IntTy,
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumSTree" [LocVar
"l767"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y766"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"total770", [], Ty2
forall loc. UrTy loc
IntTy ,
                            Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sx768", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sy769"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"total770"
                   )]

sumSTreeMainExp :: Exp2
sumSTreeMainExp :: Exp2
sumSTreeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r771") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l772" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r771")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr773", [], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l772",
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l772"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"sum774", [], Ty2
forall loc. UrTy loc
IntTy,
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumSTree" [LocVar
"l772"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr773"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"sum774"

sumSTreeProg :: Prog2
sumSTreeProg :: Prog2
sumSTreeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
stree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildSTree", FunDef2
buildSTreeFun),
                                       (LocVar
"sumSTree", FunDef2
sumSTreeFun)])
                   ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
sumSTreeMainExp, Ty2
forall loc. UrTy loc
IntTy))

--------------------------------------------------------------------------------

sumUpMainExp :: Exp2
sumUpMainExp :: Exp2
sumUpMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r530") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l531" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r530")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x532",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l531",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l531"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r536") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l537" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r536")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z538",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l537",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumUp" [LocVar
"l531",LocVar
"l537"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x532"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z538"

sumUpProg :: Prog2
sumUpProg :: Prog2
sumUpProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
stree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"sumUp", FunDef2
sumUpFun)
                                   ,(LocVar
"valueSTree", FunDef2
valueSTreeFun)
                                   ,(LocVar
"buildSTree", FunDef2
buildSTreeFun)
                                   ])
            ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
sumUpMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l537"))

--------------------------------------------------------------------------------

evenFun :: FunDef2
evenFun :: FunDef2
evenFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"even" [LocVar
"i560"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
evenFunTy Exp2
evenFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    evenFunTy :: ArrowTy2 Ty2
    evenFunTy :: ArrowTy2 Ty2
evenFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                 []
                 [Ty2
forall loc. UrTy loc
IntTy]
                 (Set Effect
forall a. Set a
S.empty)
                 (Ty2
forall loc. UrTy loc
IntTy)
                 []
                 IsBoxed
False

    evenFunBod :: Exp2
    evenFunBod :: Exp2
evenFunBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i561",[],Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
ModP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i560", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b562",[],Ty2
forall loc. UrTy loc
BoolTy,Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i561", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 Exp2 -> Exp2 -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b562")
                    (Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1) -- True
                    (Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0) -- False
{-

setEven :: Tree -> Tree
setEven tree =
  case tree of
    Leaf x -> Leaf x
    Inner sum x l r ->
      let l' = setEven l
          r' = setEven r
          v1 = value l'
          v2 = value r'
          v3 = v1 + v2
          x' = even sum
      in Inner sum x' l' r'

-}


setEvenFun :: FunDef2
setEvenFun :: FunDef2
setEvenFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"setEven" [LocVar
"tr570"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
setEvenFunTy Exp2
setEvenFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    setEvenFunTy :: ArrowTy2 Ty2
    setEvenFunTy :: ArrowTy2 Ty2
setEvenFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                    [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin571" (LocVar -> Region
VarR LocVar
"r570") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout572" (LocVar -> Region
VarR LocVar
"r757") Modality
Output]
                    [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lin571"]
                    (Set Effect
forall a. Set a
S.empty)
                    (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout572")
                    []
                    IsBoxed
False


    setEvenFunBod :: Exp2
    setEvenFunBod :: Exp2
setEvenFunBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr570")
      [ (DataCon
"Leaf", [(LocVar
"n573",LocVar
"l574")],
          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x575",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout572",
                   LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout572" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n573"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
          LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x575")

      , (DataCon
"Inner", [(LocVar
"i576",LocVar
"l577"),(LocVar
"b578",LocVar
"l579"),(LocVar
"x580",LocVar
"l581"),(LocVar
"y582",LocVar
"l583")],
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l584" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout572") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l585" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"i576" LocVar
"l584" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l586" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"b578" LocVar
"l585" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x587",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l586",
                  LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"setEven" [LocVar
"l581",LocVar
"l586"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x580"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l588" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x587" LocVar
"l586" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y589",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l588",
                  LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"setEven" [LocVar
"l583",LocVar
"l588"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y582"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v590",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"valueSTree" [LocVar
"l586"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x587"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v591",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"valueSTree" [LocVar
"l588"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y589"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v592",[],Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v590", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v591"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b593",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"even" [] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v592"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z594",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout572",
                  LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout572" DataCon
"Inner" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i576", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b593",
                                                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x587", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y589"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z594"
        )]


setEvenMainExp :: Exp2
setEvenMainExp :: Exp2
setEvenMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r592") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l593" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r592")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x594",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l593",
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l593"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r595") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l596" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r595")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z597",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l596",
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"setEven" [LocVar
"l593",LocVar
"l596"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x594"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z597"


setEvenProg :: Prog2
setEvenProg :: Prog2
setEvenProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
stree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"setEven"   , FunDef2
setEvenFun)
                                     ,(LocVar
"even"      , FunDef2
evenFun )
                                     ,(LocVar
"buildSTree", FunDef2
buildSTreeFun)
                                     ,(LocVar
"valueSTree", FunDef2
valueSTreeFun)
                                     ])
            ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
setEvenMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l596"))

--------------------------------------------------------------------------------

{-

merged  :: Tree  -> (Tree, Int)
merged tr =
  case (tr) of
    Leaf x ->
      let ret1 = Leaf x
          ret2 = x
      in (ret1, ret2)

    Inner sum x left right ->
      let (left' , v1)  = merged left
          (right', v2)  = merged right
          sum' = v1 + v2
          even'= even  sum'
          ret1 = Inner sum' even' left' right'
          ret2 = sum
      in (ret1, ret2)

-}

sumUpSetEvenFun :: FunDef2
sumUpSetEvenFun :: FunDef2
sumUpSetEvenFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"sumUpSetEven" [LocVar
"tr600"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
sumUpSetEvenFunTy Exp2
sumUpSetEvenFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    sumUpSetEvenFunTy :: ArrowTy2 Ty2
    sumUpSetEvenFunTy :: ArrowTy2 Ty2
sumUpSetEvenFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                         [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin601" (LocVar -> Region
VarR LocVar
"r600") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout602" (LocVar -> Region
VarR LocVar
"r758") Modality
Output]
                         [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lin601"]
                         (Set Effect
forall a. Set a
S.empty)
                         ([Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout602", Ty2
forall loc. UrTy loc
IntTy])
                         []
                         IsBoxed
False


    sumUpSetEvenFunBod :: Exp2
    sumUpSetEvenFunBod :: Exp2
sumUpSetEvenFunBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr600")
      [ (DataCon
"Leaf", [(LocVar
"n603",LocVar
"l604")],
          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x605",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout602",
                   LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout602" DataCon
"Leaf" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n603"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
          (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tx606",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout602", Ty2
forall loc. UrTy loc
IntTy],
                   [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x605", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n603"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
          LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tx606")

      , (DataCon
"Inner", [(LocVar
"i607",LocVar
"l608"),(LocVar
"b609",LocVar
"l610"),(LocVar
"x611",LocVar
"l612"),(LocVar
"y613",LocVar
"l622")],
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l614" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout602") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l615" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"i607" LocVar
"l614" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l616" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"b609" LocVar
"l615" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tx617",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l616", Ty2
forall loc. UrTy loc
IntTy],
                  LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumUpSetEven" [LocVar
"l612",LocVar
"l616"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x611"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x618",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l616", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tx617")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v619",[],Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tx617")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l620" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x618" LocVar
"l616" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tx621",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l620", Ty2
forall loc. UrTy loc
IntTy],
                  LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumUpSetEven" [LocVar
"l622",LocVar
"l620"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y613"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y623",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l620", Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tx621")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v624",[],Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tx621")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"v625",[],Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
AddP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v619", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v624"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b626",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"even" [] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v625"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z627",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout602",
                  LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout602" DataCon
"Inner" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v625", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b626",
                                                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x618", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y623"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tx638",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"lout602", Ty2
forall loc. UrTy loc
IntTy],
                  [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z627", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v625"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
         LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tx638")
      ]


sumUpSetEvenExp :: Exp2
sumUpSetEvenExp :: Exp2
sumUpSetEvenExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r628") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l629" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r628")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z630",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l629",
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildSTree" [LocVar
"l629"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r631") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l632" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r631")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z633",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l632", Ty2
forall loc. UrTy loc
IntTy],
                           LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumUpSetEven" [LocVar
"l629",LocVar
"l632"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z630"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z633"


sumUpSetEvenProg :: Prog2
sumUpSetEvenProg :: Prog2
sumUpSetEvenProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
stree ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"sumUpSetEven", FunDef2
sumUpSetEvenFun)
                                          ,(LocVar
"even"        , FunDef2
evenFun )
                                          ,(LocVar
"buildSTree"  , FunDef2
buildSTreeFun)
                                          ])
            ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
sumUpSetEvenExp, [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"STree" LocVar
"l632", Ty2
forall loc. UrTy loc
IntTy]))

--------------------------------------------------------------------------------

-- (data Expr
--       (VARREF Int)
--       (INTLIT Int)
--       (LETE Int Expr Expr))

-- type Var = IntTy

-- subst :: Var -> Expr -> Expr
-- subst old new ex =
--   case ex of
--     VarE v | v == old  -> unLoc new
--            | otherwise -> VarE v
--     LitE _ -> ex
--     LetE (v,t,rhs) bod | v == old  -> LetE (v,t,go rhs) bod
--                        | otherwise -> LetE (v,t,go rhs) (go bod)


ddexpr :: DDefs Ty2
ddexpr :: DDefs Ty2
ddexpr = [DDef Ty2] -> DDefs Ty2
forall a. [DDef a] -> DDefs a
fromListDD [LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, Ty2)])] -> DDef Ty2
forall a.
LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, a)])] -> DDef a
DDef (DataCon -> LocVar
toVar DataCon
"Expr") []
                      [ (DataCon
"VARREF", [(IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy)])
                      , (DataCon
"INTLIT", [(IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy)])
                      , (DataCon
"LETE"  , [(IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy),
                                    (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l"),
                                    (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l")])
                      ]]

copyExprFun :: FunDef2
copyExprFun :: FunDef2
copyExprFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"copyExpr" [LocVar
"e700"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
copyExprFunTy Exp2
copyExprFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    copyExprFunTy :: ArrowTy2 Ty2
    copyExprFunTy :: ArrowTy2 Ty2
copyExprFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                     [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin702" (LocVar -> Region
VarR LocVar
"r701") Modality
Input,
                      LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout703" (LocVar -> Region
VarR LocVar
"r759") Modality
Output]
                     [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lin702"]
                     (Set Effect
forall a. Set a
S.empty)
                     (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lout703")
                     []
                     IsBoxed
False

    copyExprFunBod :: Exp2
    copyExprFunBod :: Exp2
copyExprFunBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"e700")
                     [ (DataCon
"VARREF", [(LocVar
"v704",LocVar
"l705")],
                        LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout703" DataCon
"VARREF" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v704"]
                       )
                     , (DataCon
"LETE", [(LocVar
"v706",LocVar
"l707"), (LocVar
"rhs708", LocVar
"l709"), (LocVar
"bod710", LocVar
"l711")],
                        E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l712" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout703") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                        E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l713" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"v706" LocVar
"l712" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"rhs714",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l713",
                                 LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyExpr" [LocVar
"l709",LocVar
"l713"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"rhs708"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l715" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"rhs714" LocVar
"l713" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"bod716",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l715",
                                 LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyExpr" [LocVar
"l711", LocVar
"l715"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"bod710"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z717",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lout703",
                                 LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout703" DataCon
"LETE" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v706", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"rhs714", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"bod716"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z717")
                     ]


substFun :: FunDef2
substFun :: FunDef2
substFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"subst" [LocVar
"tr653"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
substFunTy Exp2
substFunBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    substFunTy :: ArrowTy2 Ty2
    substFunTy :: ArrowTy2 Ty2
substFunTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                  [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin651" (LocVar -> Region
VarR LocVar
"r650") Modality
Input,
                   LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin652" (LocVar -> Region
VarR LocVar
"r650") Modality
Input,
                   LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout653" (LocVar -> Region
VarR LocVar
"r760") Modality
Output]
                  [[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy,
                           DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lin651",
                           DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lin652"]]
                  (Set Effect
forall a. Set a
S.empty)
                  (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lout653")
                  []
                  IsBoxed
False

    substFunBod :: Exp2
    substFunBod :: Exp2
substFunBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"old654",[],Ty2
forall loc. UrTy loc
IntTy, Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
0 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr653")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"new655",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lin651",
                           Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
1 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr653")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"expr656",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lin652",
                           Int -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
Int -> PreExp ext loc dec -> PreExp ext loc dec
ProjE Int
2 (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr653")) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                  Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"expr656")
                  [ (DataCon
"VARREF", [(LocVar
"v657",LocVar
"l658")],
                     (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b659",[], Ty2
forall loc. UrTy loc
BoolTy,
                              Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v657", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"old654"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                     Exp2 -> Exp2 -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b659")
                     (LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyExpr" [LocVar
"lin651", LocVar
"lout653"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"new655"])
                     (LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout653" DataCon
"VARREF" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v657"]))
                  , (DataCon
"LETE", [(LocVar
"v656",LocVar
"l657"), (LocVar
"rhs658",LocVar
"l659"), (LocVar
"bod660", LocVar
"l661")],
                     (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b662",[],Ty2
forall loc. UrTy loc
BoolTy,
                              Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v656", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"old654"])
                     -- IfE (VarE "b662")
                     (E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l663" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout653") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                      E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l664" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"v656" LocVar
"l663" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"p668",[], [Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lin651", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l659"],
                               [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"old654", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"new655", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"rhs658"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"rhs665",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l664",
                               LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"subst" [LocVar
"lin651", LocVar
"l659", LocVar
"l664"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"p668"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                      E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l669" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"rhs665" LocVar
"l664" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"bod670",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l669",
                               LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"copyExpr" [LocVar
"l661", LocVar
"l669"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"bod660"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                      (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z671",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"lout653",
                               LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout653" DataCon
"LETE" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"v656", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"rhs665", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"bod670"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                      LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z671")
                    )
                  ]


substMainExp :: Exp2
substMainExp :: Exp2
substMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r720") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l721" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r720")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l722" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"l721") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l723" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
8 LocVar
"l722") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"rhs724",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l723",
                        LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l723" DataCon
"VARREF" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l724" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"rhs724" LocVar
"l723" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"bod725",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l724",
                        LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l724" DataCon
"VARREF" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
10]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"old726",[],Ty2
forall loc. UrTy loc
IntTy,Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z727",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l721",
                        LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l721" DataCon
"LETE" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"old726", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"rhs724", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"bod725"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r728") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l729" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r728")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"new730",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l729",
                        LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"l729" DataCon
"VARREF" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
42]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"p731",[],[Ty2] -> Ty2
forall loc. [UrTy loc] -> UrTy loc
ProdTy [Ty2
forall loc. UrTy loc
IntTy, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l729", DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l721"],
                        [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
[PreExp ext loc dec] -> PreExp ext loc dec
MkProdE [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"old726", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"new730", LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z727"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l730" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"new730" LocVar
"l729" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
               (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"z732",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l730",
                        LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"subst" [LocVar
"l729", LocVar
"l721", LocVar
"l730"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"p731"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
               LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"z732"


substProg :: Prog2
substProg :: Prog2
substProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddexpr ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"subst", FunDef2
substFun),
                                     (LocVar
"copyExpr", FunDef2
copyExprFun)])
            ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
substMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Expr" LocVar
"l730"))

--------------------------------------------------------------------------------

ddtree' :: DDefs Ty2
ddtree' :: DDefs Ty2
ddtree' = [DDef Ty2] -> DDefs Ty2
forall a. [DDef a] -> DDefs a
fromListDD [LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, Ty2)])] -> DDef Ty2
forall a.
LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, a)])] -> DDef a
DDef (DataCon -> LocVar
toVar DataCon
"Tree") []
                       [ (DataCon
"Leaf",[(IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy)])
                       , (DataCon
"Node",[ (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l")
                                 , (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l")])
                       , (DataCon
"Node^", [ (IsBoxed
False,Ty2
forall loc. UrTy loc
CursorTy)
                                   , (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l")
                                   , (IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l")])
                       , (DataCon
indirectionTagDataCon -> DataCon -> DataCon
forall a. [a] -> [a] -> [a]
++DataCon
"1", [(IsBoxed
False,Ty2
forall loc. UrTy loc
CursorTy)])
                       ]]

-- The rightmost function *without* copy-insertion. Gibbon should add and use
-- indirection pointers to get to the rightmost node of the tree.

indrBuildTreeFun :: FunDef2
indrBuildTreeFun :: FunDef2
indrBuildTreeFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"indrBuildTree" [LocVar
"i270"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
indrBuildTreeTy Exp2
indrBuildTreeBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    indrBuildTreeTy :: ArrowTy2 Ty2
    indrBuildTreeTy :: ArrowTy2 Ty2
indrBuildTreeTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                   [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout272" (LocVar -> Region
VarR LocVar
"r271") Modality
Output]
                   [Ty2
forall loc. UrTy loc
IntTy]
                   (Set Effect
forall a. Set a
S.empty)
                   (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout272")
                   []
                   IsBoxed
False

    indrBuildTreeBod :: Exp2
    indrBuildTreeBod :: Exp2
indrBuildTreeBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"b279",[], Ty2
forall loc. UrTy loc
BoolTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
EqIntP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i270", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
0]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       Exp2 -> Exp2 -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> PreExp ext loc dec -> PreExp ext loc dec -> PreExp ext loc dec
IfE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"b279")
                       (LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout272" DataCon
"Leaf" [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1])
                       ((LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"i273",[], Ty2
forall loc. UrTy loc
IntTy, Prim Ty2 -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
Prim dec -> [PreExp ext loc dec] -> PreExp ext loc dec
PrimAppE Prim Ty2
forall ty. Prim ty
SubP [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i270", Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
1]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"loc_indr" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
1 LocVar
"lout272") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                        E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l274" (Int -> LocVar -> PreLocExp LocVar
forall loc. Int -> loc -> PreLocExp loc
AfterConstantLE Int
8 LocVar
"loc_indr") (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"x275",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l274",
                                 LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrBuildTree" [LocVar
"l274"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i273"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l276" (LocVar -> LocVar -> IsBoxed -> PreLocExp LocVar
forall loc. LocVar -> loc -> IsBoxed -> PreLocExp loc
AfterVariableLE LocVar
"x275" LocVar
"l274" IsBoxed
True) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"y277",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l276",
                                 LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrBuildTree" [LocVar
"l276"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"i273"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"indr_cur",[],Ty2
forall loc. UrTy loc
CursorTy,E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (LocVar -> E2Ext LocVar Ty2
forall loc dec. LocVar -> E2Ext loc dec
StartOfPkdCursor LocVar
"y277"))  (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        -- LetE ("indr_node",[], PackedTy "Tree" "loc_indr",
                        --          DataConE "loc_indr" (indirectionTag++"1") [VarE "indr_cur"]) $
                        (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a278",[],DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout272",
                                 LocVar -> DataCon -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
loc -> DataCon -> [PreExp ext loc dec] -> PreExp ext loc dec
DataConE LocVar
"lout272" DataCon
"Node^" [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"indr_cur",
                                                                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"x275",
                                                                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y277"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                        LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a278")

indrBuildTreeMainExp :: Exp2
indrBuildTreeMainExp :: Exp2
indrBuildTreeMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r800") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l801" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r800")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr802", [], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l801",
                                LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrBuildTree" [LocVar
"l801"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr802"

indrBuildTreeProg :: Prog2
indrBuildTreeProg :: Prog2
indrBuildTreeProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree' ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"indrBuildTree", FunDef2
indrBuildTreeFun)])
                         ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
indrBuildTreeMainExp, DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l801"))


indrRightmostFun :: FunDef2
indrRightmostFun :: FunDef2
indrRightmostFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"indrRightmost" [LocVar
"t742"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
indrRightmostTy Exp2
indrRightmostBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
Rec FunInline
NoInline IsBoxed
False)
  where
    indrRightmostTy :: ArrowTy2 Ty2
    indrRightmostTy :: ArrowTy2 Ty2
indrRightmostTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                       [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin741" (LocVar -> Region
VarR LocVar
"r740") Modality
Input]
                       [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin741"]
                       Set Effect
forall a. Set a
S.empty
                       Ty2
forall loc. UrTy loc
IntTy
                       []
                       IsBoxed
False

indrRightmostBod :: Exp2
indrRightmostBod :: Exp2
indrRightmostBod = Exp2 -> [(DataCon, [(LocVar, LocVar)], Exp2)] -> Exp2
forall (ext :: * -> * -> *) loc dec.
PreExp ext loc dec
-> [(DataCon, [(LocVar, loc)], PreExp ext loc dec)]
-> PreExp ext loc dec
CaseE (LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"t742")
               [(DataCon
"Leaf", [(LocVar
"n746",LocVar
"l747")],
                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"n746"),
                (DataCon
"Node^", [(LocVar
"indr_y750",LocVar
"lindr_y750"),(LocVar
"x748",LocVar
"l749"), (LocVar
"y750",LocVar
"l751")],
                 (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"lm752",[],Ty2
forall loc. UrTy loc
IntTy, LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrRightmost" [LocVar
"l751"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"y750"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                 LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"lm752")]

indrRightmostMainExp :: Exp2
indrRightmostMainExp :: Exp2
indrRightmostMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r753") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l754" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r753")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr1", [], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l754",
                                LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrBuildTree" [LocVar
"l754"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
3]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a760",[], Ty2
forall loc. UrTy loc
IntTy,
                                LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrRightmost" [LocVar
"l754"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr1"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                       LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a760"

indrRightmostProg :: Prog2
indrRightmostProg :: Prog2
indrRightmostProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree' ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"indrRightmost", FunDef2
indrRightmostFun)
                                             ,(LocVar
"indrBuildTree",FunDef2
indrBuildTreeFun)])
                    ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
indrRightmostMainExp, Ty2
forall loc. UrTy loc
IntTy))

--------------------------------------------------------------------------------

indrIDFun :: FunDef2
indrIDFun :: FunDef2
indrIDFun = LocVar
-> [LocVar] -> ArrowTy (TyOf Exp2) -> Exp2 -> FunMeta -> FunDef2
forall ex.
LocVar
-> [LocVar] -> ArrowTy (TyOf ex) -> ex -> FunMeta -> FunDef ex
FunDef LocVar
"indrID" [LocVar
"tr800"] ArrowTy (TyOf Exp2)
ArrowTy2 Ty2
indrIDTy Exp2
indrIDBod (FunRec -> FunInline -> IsBoxed -> FunMeta
FunMeta FunRec
NotRec FunInline
NoInline IsBoxed
False)
  where
    indrIDTy :: ArrowTy2 Ty2
    indrIDTy :: ArrowTy2 Ty2
indrIDTy = [LRM]
-> [Ty2]
-> Set Effect
-> Ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 Ty2
forall ty2.
[LRM]
-> [ty2]
-> Set Effect
-> ty2
-> [LocRet]
-> IsBoxed
-> ArrowTy2 ty2
ArrowTy2
                [LocVar -> Region -> Modality -> LRM
LRM LocVar
"lin802" (LocVar -> Region
VarR LocVar
"r801") Modality
Input, LocVar -> Region -> Modality -> LRM
LRM LocVar
"lout803" (LocVar -> Region
VarR LocVar
"r803") Modality
Output]
                [DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lin802"]
                (Set Effect
forall a. Set a
S.empty)
                (DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout803")
                []
                IsBoxed
False

    indrIDBod :: Exp2
    indrIDBod :: Exp2
indrIDBod = (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"a804",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"lout803",
                         E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ DataCon
-> DataCon
-> (LocVar, LocVar)
-> (LocVar, LocVar)
-> Exp2
-> E2Ext LocVar Ty2
forall loc dec.
DataCon
-> DataCon
-> (loc, loc)
-> (loc, loc)
-> E2 loc dec
-> E2Ext loc dec
IndirectionE DataCon
"Tree"
                                               (DataCon
indirectionTagDataCon -> DataCon -> DataCon
forall a. [a] -> [a] -> [a]
++DataCon
"1")
                                               (LocVar
"lout803",LocVar
"r803")
                                               (LocVar
"lin802", LocVar
"r801")
                                               (Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
10)) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"a804"


--------------------------------------------------------------------------------

indrIDMainExp :: Exp2
indrIDMainExp :: Exp2
indrIDMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r806") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l807" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r806")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr1",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l807",
                         LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrBuildTree" [LocVar
"l807"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
2]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r808") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l809" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r808")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr2",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l809",
                         LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrID" [LocVar
"l807", LocVar
"l809"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr1"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"rmost",[], Ty2
forall loc. UrTy loc
IntTy,
                          LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrRightmost" [LocVar
"l809"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr2"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"rmost"

indrIDProg :: Prog2
indrIDProg :: Prog2
indrIDProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree' ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"indrBuildTree", FunDef2
indrBuildTreeFun)
                                      ,(LocVar
"indrID", FunDef2
indrIDFun)
                                      ,(LocVar
"indrRightmost",FunDef2
indrRightmostFun)])
             ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
indrIDMainExp, Ty2
forall loc. UrTy loc
IntTy))


--------------------------------------------------------------------------------

indrIDSumMainExp :: Exp2
indrIDSumMainExp :: Exp2
indrIDSumMainExp = E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r806") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l807" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r806")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr1",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l807",
                         LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"buildTree" [LocVar
"l807"] [Int -> Exp2
forall (ext :: * -> * -> *) loc dec. Int -> PreExp ext loc dec
LitE Int
10]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ Region
-> RegionSize -> Maybe RegionType -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
Region
-> RegionSize -> Maybe RegionType -> E2 loc dec -> E2Ext loc dec
LetRegionE (LocVar -> Region
VarR LocVar
"r808") RegionSize
Undefined Maybe RegionType
forall a. Maybe a
Nothing (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   E2Ext LocVar Ty2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
ext loc dec -> PreExp ext loc dec
Ext (E2Ext LocVar Ty2 -> Exp2) -> E2Ext LocVar Ty2 -> Exp2
forall a b. (a -> b) -> a -> b
$ LocVar -> PreLocExp LocVar -> Exp2 -> E2Ext LocVar Ty2
forall loc dec.
LocVar -> PreLocExp loc -> E2 loc dec -> E2Ext loc dec
LetLocE LocVar
"l809" (Region -> PreLocExp LocVar
forall loc. Region -> PreLocExp loc
StartOfRegionLE (LocVar -> Region
VarR LocVar
"r808")) (Exp2 -> E2Ext LocVar Ty2) -> Exp2 -> E2Ext LocVar Ty2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"tr2",[], DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"Tree" LocVar
"l809",
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"indrID" [LocVar
"l807", LocVar
"l809"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr1"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   (LocVar, [LocVar], Ty2, Exp2) -> Exp2 -> Exp2
forall (ext :: * -> * -> *) loc dec.
(LocVar, [loc], dec, PreExp ext loc dec)
-> PreExp ext loc dec -> PreExp ext loc dec
LetE (LocVar
"total",[], Ty2
forall loc. UrTy loc
IntTy,
                            LocVar -> [LocVar] -> [Exp2] -> Exp2
forall (ext :: * -> * -> *) loc dec.
LocVar -> [loc] -> [PreExp ext loc dec] -> PreExp ext loc dec
AppE LocVar
"sumTree" [LocVar
"l809"] [LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"tr2"]) (Exp2 -> Exp2) -> Exp2 -> Exp2
forall a b. (a -> b) -> a -> b
$
                   LocVar -> Exp2
forall (ext :: * -> * -> *) loc dec. LocVar -> PreExp ext loc dec
VarE LocVar
"total"

indrIDSumProg :: Prog2
indrIDSumProg :: Prog2
indrIDSumProg = DDefs (TyOf Exp2)
-> FunDefs Exp2 -> Maybe (Exp2, TyOf Exp2) -> Prog2
forall ex.
DDefs (TyOf ex) -> FunDefs ex -> Maybe (ex, TyOf ex) -> Prog ex
Prog DDefs (TyOf Exp2)
DDefs Ty2
ddtree' ([(LocVar, FunDef2)] -> FunDefs Exp2
forall k a. Ord k => [(k, a)] -> Map k a
M.fromList [(LocVar
"buildTree", FunDef2
buildTreeFun)
                                         ,(LocVar
"indrID", FunDef2
indrIDFun)
                                         ,(LocVar
"sumTree",FunDef2
sumTreeFun)])
                ((Exp2, Ty2) -> Maybe (Exp2, Ty2)
forall a. a -> Maybe a
Just (Exp2
indrIDSumMainExp, Ty2
forall loc. UrTy loc
IntTy))

--------------------------------------------------------------------------------

ddsnoclist :: DDefs Ty2
ddsnoclist :: DDefs Ty2
ddsnoclist = [DDef Ty2] -> DDefs Ty2
forall a. [DDef a] -> DDefs a
fromListDD [LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, Ty2)])] -> DDef Ty2
forall a.
LocVar -> [TyVar] -> [(DataCon, [(IsBoxed, a)])] -> DDef a
DDef (DataCon -> LocVar
toVar DataCon
"SnocList") []
                         [ (DataCon
"Nil"  , [])
                         , (DataCon
"Snoc" , [(IsBoxed
False,DataCon -> LocVar -> Ty2
forall loc. DataCon -> loc -> UrTy loc
PackedTy DataCon
"SnocList" LocVar
"l"),
                                      (IsBoxed
False,Ty2
forall loc. UrTy loc
IntTy)])
                         ]]