diff --git a/gibbon-compiler/src/Gibbon/Common.hs b/gibbon-compiler/src/Gibbon/Common.hs index 12460476c..d4ce648ce 100644 --- a/gibbon-compiler/src/Gibbon/Common.hs +++ b/gibbon-compiler/src/Gibbon/Common.hs @@ -8,7 +8,8 @@ module Gibbon.Common ( -- * Variables - Var(..), LocVar, RegVar, fromVar, toVar, varAppend, toEndV, toSeqV, cleanFunName + Var(..), LocVar(..), Location + , RegVar, fromVar, toVar, varAppend, toEndV, toEndVLoc, toSeqV, cleanFunName , TyVar(..), isUserTv , Symbol, intern, unintern @@ -29,7 +30,8 @@ module Gibbon.Common -- * Debugging/logging: , dbgLvl, dbgPrint, dbgPrintLn, dbgTrace, dbgTraceIt, minChatLvl - , internalError, dumpIfSet + , internalError, dumpIfSet, unwrapLocVar, singleLocVar + -- * Establish conventions for the output of #lang gibbon: , truePrinted, falsePrinted @@ -123,14 +125,22 @@ cleanFunName f = then c else '_' | c <- fromVar f ] + toEndV :: Var -> Var toEndV = varAppend "end_" +toEndVLoc :: LocVar -> LocVar +toEndVLoc loc = case loc of + Single v -> Single (toEndV v) + toSeqV :: Var -> Var toSeqV v = varAppend v (toVar "_seq") --- | Abstract location variables. -type LocVar = Var +-- | A location variable stores the abstract location. +type Location = Var + +data LocVar = Single Location + deriving (Show, Ord, Eq, Read, Generic, NFData, Out) -- | Abstract region variables. type RegVar = Var @@ -491,3 +501,10 @@ truePrinted = "#t" falsePrinted :: String falsePrinted = "#f" + +unwrapLocVar :: LocVar -> Var +unwrapLocVar locvar = case locvar of + Single loc -> loc + +singleLocVar :: Location -> LocVar +singleLocVar loc = Single loc diff --git a/gibbon-compiler/src/Gibbon/HaskellFrontend.hs b/gibbon-compiler/src/Gibbon/HaskellFrontend.hs index 8192da933..cf9435be3 100644 --- a/gibbon-compiler/src/Gibbon/HaskellFrontend.hs +++ b/gibbon-compiler/src/Gibbon/HaskellFrontend.hs @@ -154,7 +154,7 @@ data TopLevel | HInline Var deriving (Show, Eq) -type TopTyEnv = TyEnv TyScheme +type TopTyEnv = TyEnv Var TyScheme type TypeSynEnv = M.Map TyCon Ty0 desugarModule :: (Show a, Pretty a) diff --git a/gibbon-compiler/src/Gibbon/L0/Syntax.hs b/gibbon-compiler/src/Gibbon/L0/Syntax.hs index 80d91c322..50063eca5 100644 --- a/gibbon-compiler/src/Gibbon/L0/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L0/Syntax.hs @@ -497,7 +497,7 @@ isValidListElemTy0 ty -- Or we can have a special function just for L0, which is what recoverType is. -- ¯\_(ツ)_/¯ -- -recoverType :: DDefs0 -> Env2 Ty0 -> Exp0 -> Ty0 +recoverType :: DDefs0 -> Env2 Var Ty0 -> Exp0 -> Ty0 recoverType ddfs env2 ex = case ex of VarE v -> M.findWithDefault (error $ "recoverType: Unbound variable " ++ show v) v (vEnv env2) diff --git a/gibbon-compiler/src/Gibbon/L0/Typecheck.hs b/gibbon-compiler/src/Gibbon/L0/Typecheck.hs index 947a9e54b..25979607f 100644 --- a/gibbon-compiler/src/Gibbon/L0/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L0/Typecheck.hs @@ -846,9 +846,9 @@ instDataConTy ddefs dcon = do -- We can't directly use Env2 because of the way it's tied together with -- PreExp and the Expression class. We want to annotate L0 expressions -- with 'Ty0' but Gamma should store 'TyScheme's. -type Gamma = TyEnv TyScheme +type Gamma = TyEnv Var TyScheme -instance FreeVars a => FreeVars (TyEnv a) where +instance FreeVars a => FreeVars (TyEnv Var a) where gFreeVars env = foldr (S.union . gFreeVars) S.empty (M.elems env) -------------------------------------------------------------------------------- diff --git a/gibbon-compiler/src/Gibbon/L1/Syntax.hs b/gibbon-compiler/src/Gibbon/L1/Syntax.hs index f175d3aa8..3b943b077 100644 --- a/gibbon-compiler/src/Gibbon/L1/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L1/Syntax.hs @@ -39,16 +39,16 @@ instance FunctionTy Ty1 where type Exp1 = PreExp E1Ext () Ty1 -- | An L1 program. -type Prog1 = Prog Exp1 +type Prog1 = Prog Var Exp1 -- | Datatypes type DDefs1 = DDefs Ty1 type DDef1 = DDef Ty1 -- | Function definition used in L1 programs. -type FunDef1 = FunDef Exp1 +type FunDef1 = FunDef Var Exp1 -type FunDefs1 = FunDefs Exp1 +type FunDefs1 = FunDefs Var Exp1 -- | The type rperesentation used in L1. type Ty1 = UrTy () diff --git a/gibbon-compiler/src/Gibbon/L1/Typecheck.hs b/gibbon-compiler/src/Gibbon/L1/Typecheck.hs index 517f25f8a..07552bdb7 100644 --- a/gibbon-compiler/src/Gibbon/L1/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L1/Typecheck.hs @@ -31,7 +31,7 @@ import Prelude hiding (exp) -- | Typecheck a L1 expression -- -tcExp :: DDefs1 -> Env2 Ty1 -> Exp1 -> TcM Ty1 Exp1 +tcExp :: DDefs1 -> Env2 Var Ty1 -> Exp1 -> TcM Ty1 Exp1 tcExp ddfs env exp = case exp of VarE v -> lookupVar env v exp @@ -799,12 +799,12 @@ instance (Out exp) => Out (TCError exp) where type TcM a exp = Except (TCError exp) a -extendEnv :: Env2 (UrTy l) -> [(Var, (UrTy l))] -> Env2 (UrTy l) +extendEnv :: Env2 Var (UrTy l) -> [(Var, (UrTy l))] -> Env2 Var (UrTy l) extendEnv (Env2 vEnv fEnv) ((v,ty):rest) = extendEnv (Env2 (M.insert v ty vEnv) fEnv) rest extendEnv env [] = env -lookupVar :: Env2 (UrTy l) -> Var -> PreExp e () (UrTy ()) -> TcM (UrTy l) (PreExp e () (UrTy ())) +lookupVar :: Env2 Var (UrTy l) -> Var -> PreExp e () (UrTy ()) -> TcM (UrTy l) (PreExp e () (UrTy ())) lookupVar env var exp = case M.lookup var $ vEnv env of Nothing -> throwError $ VarNotFoundTC var exp @@ -816,7 +816,7 @@ tcProj _ i (ProdTy tys) = return $ tys !!! i tcProj e _i ty = throwError $ GenericTC ("Projection from non-tuple type " ++ (sdoc ty)) e -tcCases :: DDefs Ty1 -> Env2 Ty1 -> [(DataCon, [(Var, ())], Exp1)] -> TcM Ty1 Exp1 +tcCases :: DDefs Ty1 -> Env2 Var Ty1 -> [(DataCon, [(Var, ())], Exp1)] -> TcM Ty1 Exp1 tcCases ddfs env cs = do tys <- forM cs $ \(c,args',rhs) -> do let args = L.map fst args' @@ -861,7 +861,7 @@ ensureEqualTy _exp IntTy CursorTy = return CursorTy ensureEqualTy exp a b = ensureEqual exp ("Expected these types to be the same: " ++ (sdoc a) ++ ", " ++ (sdoc b)) a b -ensureArenaScope :: MonadError (TCError exp) m => exp -> Env2 a -> Maybe Var -> m () +ensureArenaScope :: MonadError (TCError exp) m => exp -> Env2 Var a -> Maybe Var -> m () ensureArenaScope exp env ar = case ar of Nothing -> throwError $ GenericTC "Expected arena annotation" exp diff --git a/gibbon-compiler/src/Gibbon/L2/Examples.hs b/gibbon-compiler/src/Gibbon/L2/Examples.hs index ce91d54c0..0a1fd42c6 100644 --- a/gibbon-compiler/src/Gibbon/L2/Examples.hs +++ b/gibbon-compiler/src/Gibbon/L2/Examples.hs @@ -26,14 +26,14 @@ import Gibbon.L2.Syntax ddtree :: DDefs Ty2 ddtree = fromListDD [DDef (toVar "Tree") [] [ ("Leaf",[(False,IntTy)]) - , ("Node",[ (False,PackedTy "Tree" "l") - , (False,PackedTy "Tree" "l")]) + , ("Node",[ (False,PackedTy "Tree" (Single "l")) + , (False,PackedTy "Tree" (Single "l"))]) ]] tTypeable :: Exp2 tTypeable = Ext $ LetRegionE (VarR "r500") Undefined Nothing $ - Ext $ LetLocE "l501" (StartOfRegionLE (VarR "r500")) $ + Ext $ LetLocE (Single "l501") (StartOfRegionLE (VarR "r500")) $ LetE ("v502",[], IntTy, LitE 42) $ (VarE "v502") @@ -45,7 +45,7 @@ testTypeable = gRecoverType ddtree emptyEnv2 tTypeable add1TraversedFun :: FunDef2 add1TraversedFun = FunDef "add1" ["tr1"] add1TraversedFunTy add1FunBod (FunMeta Rec NoInline False) - where add1TraversedFunTy = add1FunTy { arrEffs = S.fromList [Traverse "lin2"] } + where add1TraversedFunTy = add1FunTy { arrEffs = S.fromList [Traverse (Single "lin2")] } add1Fun :: FunDef2 @@ -54,68 +54,68 @@ add1Fun = FunDef "add1" ["tr1"] add1FunTy add1FunBod (FunMeta Rec NoInline False add1FunTy :: ArrowTy2 Ty2 add1FunTy = ArrowTy2 - [LRM "lin2" (VarR "r3") Input, LRM "lout4" (VarR "r750") Output] - [PackedTy "Tree" "lin2"] + [LRM (Single "lin2") (VarR "r3") Input, LRM (Single "lout4") (VarR "r750") Output] + [PackedTy "Tree" (Single "lin2")] S.empty - (PackedTy "Tree" "lout4") + (PackedTy "Tree" (Single "lout4")) [] False add1FunBod :: Exp2 add1FunBod = CaseE (VarE "tr1") - [ ("Leaf", [("n5","l6")], + [ ("Leaf", [("n5",(Single "l6"))], LetE ("v7",[],IntTy, PrimAppE AddP [VarE "n5", LitE 1]) $ - LetE ("lf8",[],PackedTy "Tree" "lout4", - DataConE "lout4" "Leaf" [VarE "v7"]) $ + LetE ("lf8",[],PackedTy "Tree" (Single "lout4"), + DataConE (Single "lout4") "Leaf" [VarE "v7"]) $ VarE "lf8") - , ("Node", [("x9","l10"),("y11","l12")], - Ext $ LetLocE "l13" (AfterConstantLE 1 "lout4") $ - LetE ("x14",[],PackedTy "Tree" "l13", - AppE "add1" ["l10","l13"] [VarE "x9"]) $ - Ext $ LetLocE "l15" (AfterVariableLE "x14" "l13" True) $ - LetE ("y16",[],PackedTy "Tree" "l15", AppE "add1" ["l12","l15"] [VarE "y11"]) $ - LetE ("z17",[],PackedTy "Tree" "lout4", - DataConE "lout4" "Node" [ VarE "x14" , VarE "y16"]) $ + , ("Node", [("x9",(Single "l10")),("y11",(Single "l12"))], + Ext $ LetLocE (Single "l13") (AfterConstantLE 1 (Single "lout4")) $ + LetE ("x14",[],PackedTy "Tree" (Single "l13"), + AppE "add1" [(Single "l10"),(Single "l13")] [VarE "x9"]) $ + Ext $ LetLocE (Single "l15") (AfterVariableLE "x14" (Single "l13") True) $ + LetE ("y16",[],PackedTy "Tree" (Single "l15"), AppE "add1" [(Single "l12"),(Single "l15")] [VarE "y11"]) $ + LetE ("z17",[],PackedTy "Tree" (Single "lout4"), + DataConE (Single "lout4") "Node" [ VarE "x14" , VarE "y16"]) $ VarE "z17") ] add1MainExp :: Exp2 add1MainExp = Ext $ LetRegionE (VarR "r99") Undefined Nothing $ - Ext $ LetLocE "l100" (StartOfRegionLE (VarR "r99")) $ - Ext $ LetLocE "l101" (AfterConstantLE 1 "l100") $ - LetE ("x102",[],PackedTy "Tree" "l101", - DataConE "l101" "Leaf" [LitE 1]) $ - Ext $ LetLocE "l103" (AfterVariableLE "x102" "l101" True) $ - LetE ("y104",[],PackedTy "Tree" "l103", - DataConE "l103" "Leaf" [LitE 2]) $ - LetE ("z105",[],PackedTy "Tree" "l100", - DataConE "l100" "Node" [VarE "x102", + Ext $ LetLocE (Single "l100") (StartOfRegionLE (VarR "r99")) $ + Ext $ LetLocE (Single "l101") (AfterConstantLE 1 (Single "l100")) $ + LetE ("x102",[],PackedTy "Tree" (Single "l101"), + DataConE (Single "l101") "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "l103") (AfterVariableLE "x102" (Single "l101") True) $ + LetE ("y104",[],PackedTy "Tree" (Single "l103"), + DataConE (Single "l103") "Leaf" [LitE 2]) $ + LetE ("z105",[],PackedTy "Tree" (Single "l100"), + DataConE (Single "l100") "Node" [VarE "x102", VarE "y104"]) $ Ext $ LetRegionE (VarR "r106") Undefined Nothing $ - Ext $ LetLocE "l107" (StartOfRegionLE (VarR "r106")) $ - LetE ("a108",[], PackedTy "Tree" "l107", - AppE "add1" ["l100", "l107"] [VarE "z105"]) $ + Ext $ LetLocE (Single "l107") (StartOfRegionLE (VarR "r106")) $ + LetE ("a108",[], PackedTy "Tree" (Single "l107"), + AppE "add1" [(Single "l100"), (Single "l107")] [VarE "z105"]) $ VarE "a108" add1Prog :: Prog2 add1Prog = Prog ddtree (M.fromList [("add1", add1Fun)]) - (Just (add1MainExp, PackedTy "Tree" "l107")) + (Just (add1MainExp, PackedTy "Tree" (Single "l107"))) -------------------------------------------------------------------------------- leafMainExp :: Exp2 leafMainExp = Ext $ LetRegionE (VarR "r150") Undefined Nothing $ - Ext $ LetLocE "l151" (StartOfRegionLE (VarR "r150")) $ - LetE ("x152",[],PackedTy "Tree" "l151", - DataConE "l151" "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "l151") (StartOfRegionLE (VarR "r150")) $ + LetE ("x152",[],PackedTy "Tree" (Single "l151"), + DataConE (Single "l151") "Leaf" [LitE 1]) $ VarE "x152" leafProg :: Prog2 -leafProg = Prog ddtree M.empty (Just (leafMainExp, PackedTy "Tree" "l151")) +leafProg = Prog ddtree M.empty (Just (leafMainExp, PackedTy "Tree" (Single "l151"))) -------------------------------------------------------------------------------- @@ -123,20 +123,20 @@ leafProg = Prog ddtree M.empty (Just (leafMainExp, PackedTy "Tree" "l151")) -- writes node nodeMainExp :: Exp2 nodeMainExp = Ext $ LetRegionE (VarR "r155") Undefined Nothing $ - Ext $ LetLocE "l156" (StartOfRegionLE (VarR "r155")) $ - Ext $ LetLocE "l157" (AfterConstantLE 1 "l156") $ - LetE ("x158",[],PackedTy "Tree" "l157", - DataConE "l157" "Leaf" [LitE 1]) $ - Ext $ LetLocE "l159" (AfterVariableLE "x158" "l157" True) $ - LetE ("y160",[],PackedTy "Tree" "l159", - DataConE "l159" "Leaf" [LitE 2]) $ - LetE ("z161",[],PackedTy "Tree" "l156", - DataConE "l156" "Node" [VarE "x158", VarE "y160"]) $ + Ext $ LetLocE (Single "l156") (StartOfRegionLE (VarR "r155")) $ + Ext $ LetLocE (Single "l157") (AfterConstantLE 1 (Single "l156")) $ + LetE ("x158",[],PackedTy "Tree" (Single "l157"), + DataConE (Single "l157") "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "l159") (AfterVariableLE "x158" (Single "l157") True) $ + LetE ("y160",[],PackedTy "Tree" (Single "l159"), + DataConE (Single "l159") "Leaf" [LitE 2]) $ + LetE ("z161",[],PackedTy "Tree" (Single "l156"), + DataConE (Single "l156") "Node" [VarE "x158", VarE "y160"]) $ VarE "z161" nodeProg :: Prog2 -nodeProg = Prog ddtree M.empty (Just (nodeMainExp, PackedTy "Tree" "l156")) +nodeProg = Prog ddtree M.empty (Just (nodeMainExp, PackedTy "Tree" (Single "l156"))) -------------------------------------------------------------------------------- @@ -147,10 +147,10 @@ id1Fun = FunDef "id1" ["tr18"] idFunTy idFunBod (FunMeta NotRec NoInline False) idFunTy :: ArrowTy2 Ty2 idFunTy = ArrowTy2 - [LRM "lin19" (VarR "r20") Input, LRM "lout21" (VarR "r751") Output] - [PackedTy "Tree" "lin19"] + [LRM (Single "lin19") (VarR "r20") Input, LRM (Single "lout21") (VarR "r751") Output] + [PackedTy "Tree" (Single "lin19")] (S.empty) - (PackedTy "Tree" "lout21") + (PackedTy "Tree" (Single "lout21")) [] False @@ -164,49 +164,49 @@ copyTreeFun :: FunDef2 copyTreeFun = FunDef "copyTree" ["tr22"] copyFunTy copyBod (FunMeta NotRec NoInline False) where copyFunTy = ArrowTy2 - [LRM "lin23" (VarR "r24") Input, LRM "lout25" (VarR "r752") Output] - [PackedTy "Tree" "lin23"] + [LRM (Single "lin23") (VarR "r24") Input, LRM (Single "lout25") (VarR "r752") Output] + [PackedTy "Tree" (Single "lin23")] S.empty - (PackedTy "Tree" "lout25") + (PackedTy "Tree" (Single "lout25")) [] False copyBod = CaseE (VarE "tr22") - [ ("Leaf", [("n27","lin26")], - LetE ("n28",[],PackedTy "Tree" "lout25", - DataConE "lout25" "Leaf" [VarE "n27"]) $ + [ ("Leaf", [("n27",(Single "lin26"))], + LetE ("n28",[],PackedTy "Tree" (Single "lout25"), + DataConE (Single "lout25") "Leaf" [VarE "n27"]) $ VarE "n28") - , ("Node", [("x29","lx30"),("y31","ly32")], - Ext $ LetLocE "lx33" (AfterConstantLE 1 "lout25") $ - LetE ("x34", [], PackedTy "Tree" "lx33", - AppE "copyTree" ["lx30","lx33"] [VarE "x29"]) $ - Ext $ LetLocE "ly35" (AfterVariableLE "x34" "lx33" True) $ - LetE ("y36", [], PackedTy "Tree" "ly35", - AppE "copyTree" ["ly32","ly35"] [VarE "y31"]) $ - DataConE "lout25" "Node" [VarE "x34", VarE "y36"]) + , ("Node", [("x29",(Single "lx30")),("y31",(Single "ly32"))], + Ext $ LetLocE (Single "lx33") (AfterConstantLE 1 (Single "lout25")) $ + LetE ("x34", [], PackedTy "Tree" (Single "lx33"), + AppE "copyTree" [(Single "lx30"),(Single "lx33")] [VarE "x29"]) $ + Ext $ LetLocE (Single "ly35") (AfterVariableLE "x34" (Single "lx33") True) $ + LetE ("y36", [], PackedTy "Tree" (Single "ly35"), + AppE "copyTree" [(Single "ly32"),(Single "ly35")] [VarE "y31"]) $ + DataConE (Single "lout25") "Node" [VarE "x34", VarE "y36"]) ] copyTreeMainExp :: Exp2 copyTreeMainExp = Ext $ LetRegionE (VarR "r200") Undefined Nothing $ - Ext $ LetLocE "l201" (StartOfRegionLE (VarR "r200")) $ - Ext $ LetLocE "l202" (AfterConstantLE 1 "l201") $ - LetE ("x203",[],PackedTy "Tree" "l202", - DataConE "l202" "Leaf" [LitE 1]) $ - Ext $ LetLocE "r204" (AfterVariableLE "x203" "l202" True) $ - LetE ("y205",[],PackedTy "Tree" "r204", - DataConE "r204" "Leaf" [LitE 2]) $ - LetE ("z206",[],PackedTy "Tree" "l201", - DataConE "l201" "Node" [VarE "x203", VarE "y205"]) $ + Ext $ LetLocE (Single "l201") (StartOfRegionLE (VarR "r200")) $ + Ext $ LetLocE (Single "l202") (AfterConstantLE 1 (Single "l201")) $ + LetE ("x203",[],PackedTy "Tree" (Single "l202"), + DataConE (Single "l202") "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "r204") (AfterVariableLE "x203" (Single "l202") True) $ + LetE ("y205",[],PackedTy "Tree" (Single "r204"), + DataConE (Single "r204") "Leaf" [LitE 2]) $ + LetE ("z206",[],PackedTy "Tree" (Single "l201"), + DataConE (Single "l201") "Node" [VarE "x203", VarE "y205"]) $ Ext $ LetRegionE (VarR "r207") Undefined Nothing $ - Ext $ LetLocE "l208" (StartOfRegionLE (VarR "r207")) $ - LetE ("a209",[], PackedTy "Tree" "l208", - AppE "copyTree" ["l201", "l208"] [VarE "z206"]) $ + Ext $ LetLocE (Single "l208") (StartOfRegionLE (VarR "r207")) $ + LetE ("a209",[], PackedTy "Tree" (Single "l208"), + AppE "copyTree" [(Single "l201"), (Single "l208")] [VarE "z206"]) $ VarE "a209" copyTreeProg :: Prog2 copyTreeProg = Prog ddtree (M.fromList [("copyTree", copyTreeFun)]) $ - Just (copyTreeMainExp, PackedTy "Tree" "l208") + Just (copyTreeMainExp, PackedTy "Tree" (Single "l208")) -------------------------------------------------------------------------------- @@ -215,10 +215,10 @@ id2Fun = FunDef "id2" ["tr41"] id2Ty id2Bod (FunMeta NotRec NoInline False) where id2Ty :: ArrowTy2 Ty2 id2Ty = ArrowTy2 - [LRM "lin37" (VarR "r38") Input, LRM "lout39" (VarR "r753") Output] - [PackedTy "Tree" "lin37"] + [LRM (Single "lin37") (VarR "r38") Input, LRM (Single "lout39") (VarR "r753") Output] + [PackedTy "Tree" (Single "lin37")] (S.empty) - (PackedTy "Tree" "lout39") + (PackedTy "Tree" (Single "lout39")) [] False @@ -232,30 +232,30 @@ id2Prog = Prog ddtree (M.fromList [("id2", id2Fun)]) Nothing -------------------------------------------------------------------------------- copyOnId1Prog :: Prog2 -copyOnId1Prog = Prog ddtree funs $ Just (copyOnId1MainExp, PackedTy "Tree" "l228") +copyOnId1Prog = Prog ddtree funs $ Just (copyOnId1MainExp, PackedTy "Tree" (Single "l228")) where funs = M.fromList [("copyTree" , copyTreeFun), ("id1WithCopy", id1WithCopyFun)] copyOnId1MainExp :: Exp2 copyOnId1MainExp = Ext $ LetRegionE (VarR "r220") Undefined Nothing $ - Ext $ LetLocE "l221" (StartOfRegionLE (VarR "r220")) $ - Ext $ LetLocE "l222" (AfterConstantLE 1 "l221") $ - LetE ("l223",[],PackedTy "Tree" "l222", - DataConE "l222" "Leaf" [LitE 1]) $ - Ext $ LetLocE "l224" (AfterVariableLE "l223" "l222" True) $ - LetE ("l225",[],PackedTy "Tree" "l224", - DataConE "l224" "Leaf" [LitE 2]) $ - LetE ("z226",[],PackedTy "Tree" "l221", - DataConE "l221" "Node" [VarE "l223", VarE "l225"]) $ + Ext $ LetLocE (Single "l221") (StartOfRegionLE (VarR "r220")) $ + Ext $ LetLocE (Single "l222") (AfterConstantLE 1 (Single "l221")) $ + LetE ("l223",[],PackedTy "Tree" (Single "l222"), + DataConE (Single "l222") "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "l224") (AfterVariableLE "l223" (Single "l222") True) $ + LetE ("l225",[],PackedTy "Tree" (Single "l224"), + DataConE (Single "l224") "Leaf" [LitE 2]) $ + LetE ("z226",[],PackedTy "Tree" (Single "l221"), + DataConE (Single "l221") "Node" [VarE "l223", VarE "l225"]) $ Ext $ LetRegionE (VarR "r227") Undefined Nothing $ - Ext $ LetLocE "l228" (StartOfRegionLE (VarR "r227")) $ - LetE ("a229",[], PackedTy "Tree" "l228", - AppE "id1WithCopy" ["l221", "l228"] [VarE "z226"]) $ + Ext $ LetLocE (Single "l228") (StartOfRegionLE (VarR "r227")) $ + LetE ("a229",[], PackedTy "Tree" (Single "l228"), + AppE "id1WithCopy" [(Single "l221"), (Single "l228")] [VarE "z226"]) $ VarE "a229" id1WithCopyFun :: FunDef2 -id1WithCopyFun = id1Fun { funBody = AppE "copyTree" ["lin19","lout21"] +id1WithCopyFun = id1Fun { funBody = AppE "copyTree" [(Single "lin19"),(Single "lout21")] [VarE "tr18"] , funName = "id1WithCopy" } @@ -313,8 +313,8 @@ leftmostFun = FunDef "leftmost" ["t111"] leftmostTy leftmostBod (FunMeta Rec NoI where leftmostTy :: ArrowTy2 Ty2 leftmostTy = ArrowTy2 - [LRM "lin112" (VarR "r113") Input] - [PackedTy "Tree" "lin112"] + [LRM (Single "lin112") (VarR "r113") Input] + [PackedTy "Tree" (Single "lin112")] (S.empty) (IntTy) [] @@ -322,25 +322,25 @@ leftmostFun = FunDef "leftmost" ["t111"] leftmostTy leftmostBod (FunMeta Rec NoI leftmostBod :: Exp2 leftmostBod = CaseE (VarE "t111") - [("Leaf", [("n114","l115")], + [("Leaf", [("n114",(Single "l115"))], VarE "n114"), - ("Node", [("x117","l118"), ("y119","l120")], - LetE ("lm121",[],IntTy, AppE "leftmost" ["l118"] [VarE "x117"]) $ + ("Node", [("x117",(Single "l118")), ("y119",(Single "l120"))], + LetE ("lm121",[],IntTy, AppE "leftmost" [(Single "l118")] [VarE "x117"]) $ VarE "lm121")] leftmostMainExp :: Exp2 leftmostMainExp = Ext $ LetRegionE (VarR "r122") Undefined Nothing $ - Ext $ LetLocE "l123" (StartOfRegionLE (VarR "r122")) $ - Ext $ LetLocE "l124" (AfterConstantLE 1 "l123") $ - LetE ("x125",[],PackedTy "Tree" "l124", - DataConE "l124" "Leaf" [LitE 1]) $ - Ext $ LetLocE "l126" (AfterVariableLE "x125" "l124" True) $ - LetE ("y128",[],PackedTy "Tree" "l126", - DataConE "l126" "Leaf" [LitE 2]) $ - LetE ("z127",[],PackedTy "Tree" "l123", - DataConE "l123" "Node" [VarE "x125", VarE "y128"]) $ + Ext $ LetLocE (Single "l123") (StartOfRegionLE (VarR "r122")) $ + Ext $ LetLocE (Single "l124") (AfterConstantLE 1 (Single "l123")) $ + LetE ("x125",[],PackedTy "Tree" (Single "l124"), + DataConE (Single "l124") "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "l126") (AfterVariableLE "x125" (Single "l124") True) $ + LetE ("y128",[],PackedTy "Tree" (Single "l126"), + DataConE (Single "l126") "Leaf" [LitE 2]) $ + LetE ("z127",[],PackedTy "Tree" (Single "l123"), + DataConE (Single "l123") "Node" [VarE "x125", VarE "y128"]) $ LetE ("a131",[], IntTy, - AppE "leftmost" ["l123"] [VarE "z127"]) $ + AppE "leftmost" [(Single "l123")] [VarE "z127"]) $ VarE "a131" leftmostProg :: Prog2 @@ -354,8 +354,8 @@ rightmostFun = FunDef "rightmost" ["t242"] rightmostTy rightmostBod (FunMeta Rec where rightmostTy :: ArrowTy2 Ty2 rightmostTy = ArrowTy2 - [LRM "lin241" (VarR "r240") Input] - [PackedTy "Tree" "lin241"] + [LRM (Single "lin241") (VarR "r240") Input] + [PackedTy "Tree" (Single "lin241")] (S.empty) (IntTy) [] @@ -363,29 +363,29 @@ rightmostFun = FunDef "rightmost" ["t242"] rightmostTy rightmostBod (FunMeta Rec rightmostBod :: Exp2 rightmostBod = CaseE (VarE "t242") - [("Leaf", [("n246","l247")], + [("Leaf", [("n246",(Single "l247"))], VarE "n246"), - ("Node", [("x248","l249"), ("y250","l251")], + ("Node", [("x248",(Single "l249")), ("y250",(Single "l251"))], -- Ext $ LetRegionE (VarR "r252") Undefined Nothing $ -- Ext $ LetLocE "l253" (StartOfRegionLE (VarR "r252")) $ -- LetE ("x254",[],PackedTy "Tree" "l253", -- AppE "copyTree" ["l249", "l253"] (VarE "x248")) $ - AppE "rightmost" ["l251"] [VarE "y250"] + AppE "rightmost" [(Single "l251")] [VarE "y250"] )] rightmostMainExp :: Exp2 rightmostMainExp = Ext $ LetRegionE (VarR "r253") Undefined Nothing $ - Ext $ LetLocE "l254" (StartOfRegionLE (VarR "r253")) $ - Ext $ LetLocE "l255" (AfterConstantLE 1 "l254") $ - LetE ("x256",[],PackedTy "Tree" "l255", - DataConE "l255" "Leaf" [LitE 1]) $ - Ext $ LetLocE "l257" (AfterVariableLE "x256" "l255" True) $ - LetE ("y258",[],PackedTy "Tree" "l257", - DataConE "l257" "Leaf" [LitE 2]) $ - LetE ("z259",[],PackedTy "Tree" "l254", - DataConE "l254" "Node" [VarE "x256", VarE "y258"]) $ + Ext $ LetLocE (Single "l254") (StartOfRegionLE (VarR "r253")) $ + Ext $ LetLocE (Single "l255") (AfterConstantLE 1 (Single "l254")) $ + LetE ("x256",[],PackedTy "Tree" (Single "l255"), + DataConE (Single "l255") "Leaf" [LitE 1]) $ + Ext $ LetLocE (Single "l257") (AfterVariableLE "x256" (Single "l255") True) $ + LetE ("y258",[],PackedTy "Tree" (Single "l257"), + DataConE (Single "l257") "Leaf" [LitE 2]) $ + LetE ("z259",[],PackedTy "Tree" (Single "l254"), + DataConE (Single "l254") "Node" [VarE "x256", VarE "y258"]) $ LetE ("a260",[], IntTy, - AppE "rightmost" ["l254"] [VarE "z259"]) $ + AppE "rightmost" [(Single "l254")] [VarE "z259"]) $ VarE "a260" rightmostProg :: Prog2 @@ -400,24 +400,24 @@ buildLeafFun = FunDef "buildLeaf" ["i125"] buildLeafTy buildLeafBod (FunMeta Rec where buildLeafTy :: ArrowTy2 Ty2 buildLeafTy = ArrowTy2 - [LRM "lout126" (VarR "r127") Output] + [LRM (Single "lout126") (VarR "r127") Output] [IntTy] (S.empty) - (PackedTy "Tree" "lout126") + (PackedTy "Tree" (Single "lout126")) [] False buildLeafBod :: Exp2 - buildLeafBod = DataConE "lout126" "Leaf" [VarE "i125"] + buildLeafBod = DataConE (Single "lout126") "Leaf" [VarE "i125"] buildLeafMainExp :: Exp2 buildLeafMainExp = Ext $ LetRegionE (VarR "r128") Undefined Nothing $ - Ext $ LetLocE "l129" (StartOfRegionLE (VarR "r128")) $ - AppE "buildLeaf" ["l129"] [LitE 42] + Ext $ LetLocE (Single "l129") (StartOfRegionLE (VarR "r128")) $ + AppE "buildLeaf" [(Single "l129")] [LitE 42] buildLeafProg :: Prog2 -buildLeafProg = Prog ddtree (M.fromList [("buildLeaf", buildLeafFun)]) (Just (buildLeafMainExp, PackedTy "Tree" "l129")) +buildLeafProg = Prog ddtree (M.fromList [("buildLeaf", buildLeafFun)]) (Just (buildLeafMainExp, PackedTy "Tree" (Single "l129"))) -------------------------------------------------------------------------------- @@ -427,36 +427,36 @@ buildTreeFun = FunDef "buildTree" ["i270"] buildTreeTy buildTreeBod (FunMeta Rec where buildTreeTy :: ArrowTy2 Ty2 buildTreeTy = ArrowTy2 - [LRM "lout272" (VarR "r271") Output] + [LRM (Single "lout272") (VarR "r271") Output] [IntTy] (S.empty) - (PackedTy "Tree" "lout272") + (PackedTy "Tree" (Single "lout272")) [] False buildTreeBod :: Exp2 buildTreeBod = LetE ("b279",[], BoolTy, PrimAppE EqIntP [VarE "i270", LitE 0]) $ IfE (VarE "b279") - (DataConE "lout272" "Leaf" [LitE 1]) + (DataConE (Single "lout272") "Leaf" [LitE 1]) (LetE ("i273",[], IntTy, PrimAppE SubP [VarE "i270", LitE 1]) $ - Ext $ LetLocE "l274" (AfterConstantLE 1 "lout272") $ - LetE ("x275",[],PackedTy "Tree" "l274", - AppE "buildTree" ["l274"] [VarE "i273"]) $ - Ext $ LetLocE "l276" (AfterVariableLE "x275" "l274" True) $ - LetE ("y277",[],PackedTy "Tree" "l276", - AppE "buildTree" ["l276"] [VarE "i273"]) $ - LetE ("a278",[],PackedTy "Tree" "lout272", - DataConE "lout272" "Node" [VarE "x275", VarE "y277"]) $ + Ext $ LetLocE (Single "l274") (AfterConstantLE 1 (Single "lout272")) $ + LetE ("x275",[],PackedTy "Tree" (Single "l274"), + AppE "buildTree" [(Single "l274")] [VarE "i273"]) $ + Ext $ LetLocE (Single "l276") (AfterVariableLE "x275" (Single "l274") True) $ + LetE ("y277",[],PackedTy "Tree" (Single "l276"), + AppE "buildTree" [(Single "l276")] [VarE "i273"]) $ + LetE ("a278",[],PackedTy "Tree" (Single "lout272"), + DataConE (Single "lout272") "Node" [VarE "x275", VarE "y277"]) $ VarE "a278") buildTreeMainExp :: Exp2 buildTreeMainExp = Ext $ LetRegionE (VarR "r279") Undefined Nothing $ - Ext $ LetLocE "l280" (StartOfRegionLE (VarR "r279")) $ - AppE "buildTree" ["l280"] [LitE 3] + Ext $ LetLocE (Single "l280") (StartOfRegionLE (VarR "r279")) $ + AppE "buildTree" [(Single "l280")] [LitE 3] buildTreeProg :: Prog2 -buildTreeProg = Prog ddtree (M.fromList [("buildTree", buildTreeFun)]) (Just (buildTreeMainExp, PackedTy "Tree" "l280")) +buildTreeProg = Prog ddtree (M.fromList [("buildTree", buildTreeFun)]) (Just (buildTreeMainExp, PackedTy "Tree" (Single "l280"))) -------------------------------------------------------------------------------- @@ -467,35 +467,35 @@ buildTwoTreesFun = FunDef "buildTwoTrees" ["i750"] buildTreeTy buildTreeBod (Fun where buildTreeTy :: ArrowTy2 Ty2 buildTreeTy = ArrowTy2 - [LRM "lout752" (VarR "r751") Output, LRM "lout754" (VarR "r753") Output] + [LRM (Single "lout752") (VarR "r751") Output, LRM (Single "lout754") (VarR "r753") Output] [IntTy] (S.empty) - (ProdTy [PackedTy "Tree" "lout752", PackedTy "Tree" "lout754"]) + (ProdTy [PackedTy "Tree" (Single "lout752"), PackedTy "Tree" (Single "lout754")]) [] False buildTreeBod :: Exp2 - buildTreeBod = LetE ("tree1",[],PackedTy "Tree" "lout752", - AppE "buildTree" ["lout752"] [VarE "i750"]) $ - LetE ("tree2",[],PackedTy "Tree" "lout754", - AppE "buildTree" ["lout754"] [VarE "i750"]) $ - LetE ("a755",[], ProdTy [PackedTy "Tree" "lout752", PackedTy "Tree" "lout754"], + buildTreeBod = LetE ("tree1",[],PackedTy "Tree" (Single "lout752"), + AppE "buildTree" [(Single "lout752")] [VarE "i750"]) $ + LetE ("tree2",[],PackedTy "Tree" (Single "lout754"), + AppE "buildTree" [(Single "lout754")] [VarE "i750"]) $ + LetE ("a755",[], ProdTy [PackedTy "Tree" (Single "lout752"), PackedTy "Tree" (Single "lout754")], MkProdE [VarE "tree1", VarE "tree2"]) $ VarE "a755" buildTwoTreesMainExp :: Exp2 buildTwoTreesMainExp = Ext $ LetRegionE (VarR "r756") Undefined Nothing $ - Ext $ LetLocE "l757" (StartOfRegionLE (VarR "r756")) $ + Ext $ LetLocE (Single "l757") (StartOfRegionLE (VarR "r756")) $ Ext $ LetRegionE (VarR "r758") Undefined Nothing $ - Ext $ LetLocE "l759" (StartOfRegionLE (VarR "r758")) $ - LetE ("treeprod", [], ProdTy [PackedTy "Tree" "lout757", PackedTy "Tree" "lout759"], - AppE "buildTwoTrees" ["l757", "l759"] [LitE 2]) $ + Ext $ LetLocE (Single "l759") (StartOfRegionLE (VarR "r758")) $ + LetE ("treeprod", [], ProdTy [PackedTy "Tree" (Single "lout757"), PackedTy "Tree" (Single "lout759")], + AppE "buildTwoTrees" [(Single "l757"), (Single "l759")] [LitE 2]) $ VarE "treeprod" buildTwoTreesProg :: Prog2 buildTwoTreesProg = Prog ddtree (M.fromList [("buildTree", buildTreeFun), ("buildTwoTrees", buildTwoTreesFun)]) - (Just (buildTwoTreesMainExp, ProdTy [PackedTy "Tree" "lout757", PackedTy "Tree" "lout759"])) + (Just (buildTwoTreesMainExp, ProdTy [PackedTy "Tree" (Single "lout757"), PackedTy "Tree" (Single "lout759")])) -------------------------------------------------------------------------------- @@ -504,50 +504,50 @@ buildTreeSumFun = FunDef "buildTreeSum" ["i302"] buildTreeSumTy buildTreeSumBod where buildTreeSumTy :: ArrowTy2 Ty2 buildTreeSumTy = ArrowTy2 - [LRM "lout301" (VarR "r300") Output] + [LRM (Single "lout301") (VarR "r300") Output] [IntTy] (S.empty) - (ProdTy [IntTy, PackedTy "Tree" "lout301"]) + (ProdTy [IntTy, PackedTy "Tree" (Single "lout301")]) [] False buildTreeSumBod :: Exp2 buildTreeSumBod = LetE ("b303",[], BoolTy, PrimAppE EqIntP [VarE "i302", LitE 0]) $ IfE (VarE "b303") - (LetE ("c316",[],PackedTy "Tree" "lout301", - DataConE "lout301" "Leaf" [LitE 1]) $ - LetE ("t317",[],ProdTy [IntTy, PackedTy "Tree" "lout301"], + (LetE ("c316",[],PackedTy "Tree" (Single "lout301"), + DataConE (Single "lout301") "Leaf" [LitE 1]) $ + LetE ("t317",[],ProdTy [IntTy, PackedTy "Tree" (Single "lout301")], MkProdE [LitE 1, VarE "c316"]) $ VarE "t317") (LetE ("i303",[], IntTy, PrimAppE SubP [VarE "i302", LitE 1]) $ - Ext $ LetLocE "l304" (AfterConstantLE 1 "lout301") $ - LetE ("t318",[],ProdTy [IntTy, PackedTy "Tree" "l304"], - AppE "buildTreeSum" ["l304"] [VarE "i303"]) $ + Ext $ LetLocE (Single "l304") (AfterConstantLE 1 (Single "lout301")) $ + LetE ("t318",[],ProdTy [IntTy, PackedTy "Tree" (Single "l304")], + AppE "buildTreeSum" [(Single "l304")] [VarE "i303"]) $ LetE ("i309",[],IntTy, ProjE 0 (VarE "t318")) $ - LetE ("x305",[],PackedTy "Tree" "l304", ProjE 1 (VarE "t318")) $ - Ext $ LetLocE "l306" (AfterVariableLE "x305" "l304" True) $ - LetE ("t319",[],ProdTy [IntTy, PackedTy "Tree" "l306"], - AppE "buildTreeSum" ["l306"] [VarE "i303"]) $ + LetE ("x305",[],PackedTy "Tree" (Single "l304"), ProjE 1 (VarE "t318")) $ + Ext $ LetLocE (Single "l306") (AfterVariableLE "x305" (Single "l304") True) $ + LetE ("t319",[],ProdTy [IntTy, PackedTy "Tree" (Single "l306")], + AppE "buildTreeSum" [(Single "l306")] [VarE "i303"]) $ LetE ("i310",[],IntTy, ProjE 0 (VarE "t319")) $ - LetE ("y307",[],PackedTy "Tree" "l306", ProjE 1 (VarE "t319")) $ + LetE ("y307",[],PackedTy "Tree" (Single "l306"), ProjE 1 (VarE "t319")) $ LetE ("j311",[],IntTy, PrimAppE AddP [VarE "i309", VarE "i310"]) $ - LetE ("a308",[],PackedTy "Tree" "lout301", - DataConE "lout301" "Node" [VarE "x305", VarE "y307"]) $ - LetE ("b312",[], ProdTy [IntTy, PackedTy "Tree" "lout301"], + LetE ("a308",[],PackedTy "Tree" (Single "lout301"), + DataConE (Single "lout301") "Node" [VarE "x305", VarE "y307"]) $ + LetE ("b312",[], ProdTy [IntTy, PackedTy "Tree" (Single "lout301")], MkProdE [VarE "j311", VarE "a308"]) $ VarE "b312") buildTreeSumMainExp :: Exp2 buildTreeSumMainExp = Ext $ LetRegionE (VarR "r313") Undefined Nothing $ - Ext $ LetLocE "l314" (StartOfRegionLE (VarR "r313")) $ - LetE ("z315",[],ProdTy [IntTy, PackedTy "Tree" "l314"], - AppE "buildTreeSum" ["l314"] [LitE 3]) $ + Ext $ LetLocE (Single "l314") (StartOfRegionLE (VarR "r313")) $ + LetE ("z315",[],ProdTy [IntTy, PackedTy "Tree" (Single "l314")], + AppE "buildTreeSum" [(Single "l314")] [LitE 3]) $ VarE "z315" buildTreeSumProg :: Prog2 -buildTreeSumProg = Prog ddtree (M.fromList [("buildTreeSum", buildTreeSumFun)]) (Just (buildTreeSumMainExp, ProdTy [IntTy, PackedTy "Tree" "l314"])) +buildTreeSumProg = Prog ddtree (M.fromList [("buildTreeSum", buildTreeSumFun)]) (Just (buildTreeSumMainExp, ProdTy [IntTy, PackedTy "Tree" (Single "l314")])) -------------------------------------------------------------------------------- @@ -556,8 +556,8 @@ sumTreeFun = FunDef "sumTree" ["tr762"] sumTreeTy sumTreeBod (FunMeta Rec NoInli where sumTreeTy :: ArrowTy2 Ty2 sumTreeTy = ArrowTy2 - [LRM "lin761" (VarR "r760") Input] - [PackedTy "Tree" "lin761"] + [LRM (Single "lin761") (VarR "r760") Input] + [PackedTy "Tree" (Single "lin761")] (S.empty) (IntTy) [] @@ -565,13 +565,13 @@ sumTreeFun = FunDef "sumTree" ["tr762"] sumTreeTy sumTreeBod (FunMeta Rec NoInli sumTreeBod :: Exp2 sumTreeBod = CaseE (VarE "tr762") - [ ("Leaf", [("n763", "l764")], + [ ("Leaf", [("n763", (Single "l764"))], VarE "n763") - , ("Node", [("x764","l765"), ("y766","l767")], + , ("Node", [("x764",(Single "l765")), ("y766", (Single "l767"))], LetE ("sx768", [], IntTy, - AppE "sumTree" ["l765"] [VarE "x764"]) $ + AppE "sumTree" [(Single "l765")] [VarE "x764"]) $ LetE ("sy769", [], IntTy, - AppE "sumTree" ["l767"] [VarE "y766"]) $ + AppE "sumTree" [(Single "l767")] [VarE "y766"]) $ LetE ("total770", [], IntTy , PrimAppE AddP [VarE "sx768", VarE "sy769"]) $ VarE "total770" @@ -579,11 +579,11 @@ sumTreeFun = FunDef "sumTree" ["tr762"] sumTreeTy sumTreeBod (FunMeta Rec NoInli sumTreeMainExp :: Exp2 sumTreeMainExp = Ext $ LetRegionE (VarR "r771") Undefined Nothing $ - Ext $ LetLocE "l772" (StartOfRegionLE (VarR "r771")) $ - LetE ("tr773", [], PackedTy "Tree" "l772", - AppE "buildTree" ["l772"] [LitE 3]) $ + Ext $ LetLocE (Single "l772") (StartOfRegionLE (VarR "r771")) $ + LetE ("tr773", [], PackedTy "Tree" (Single "l772"), + AppE "buildTree" [(Single "l772")] [LitE 3]) $ LetE ("sum774", [], IntTy, - AppE "sumTree" ["l772"] [VarE "tr773"]) $ + AppE "sumTree" [(Single "l772")] [VarE "tr773"]) $ VarE "sum774" sumTreeProg :: Prog2 @@ -596,35 +596,35 @@ sumTreeProg = Prog ddtree (M.fromList [("buildTree", buildTreeFun), printTupMainExp :: Exp2 printTupMainExp = Ext $ LetRegionE (VarR "r325") Undefined Nothing $ - Ext $ LetLocE "l326" (StartOfRegionLE (VarR "r325")) $ + Ext $ LetLocE (Single "l326") (StartOfRegionLE (VarR "r325")) $ LetE ("i327",[], IntTy, LitE 42) $ - LetE ("x328",[], PackedTy "Tree" "l326", - DataConE "l326" "Leaf" [LitE 1]) $ - LetE ("t329",[], ProdTy [IntTy, PackedTy "Tree" "l326"], + LetE ("x328",[], PackedTy "Tree" (Single "l326"), + DataConE (Single "l326") "Leaf" [LitE 1]) $ + LetE ("t329",[], ProdTy [IntTy, PackedTy "Tree" (Single "l326")], MkProdE [VarE "i327", VarE "x328"]) $ VarE "t329" printTupProg :: Prog2 -printTupProg = Prog ddtree M.empty (Just (printTupMainExp, ProdTy [IntTy, PackedTy "Tree" "l326"])) +printTupProg = Prog ddtree M.empty (Just (printTupMainExp, ProdTy [IntTy, PackedTy "Tree" (Single "l326")])) -------------------------------------------------------------------------------- printTupMainExp2 :: Exp2 printTupMainExp2 = Ext $ LetRegionE (VarR "r400") Undefined Nothing $ - Ext $ LetLocE "l401" (StartOfRegionLE (VarR "r400")) $ - LetE ("x402",[], PackedTy "Tree" "l401", - AppE "buildTree" ["l401"] [LitE 2]) $ - Ext $ LetLocE "l403" (AfterVariableLE "x402" "l401" True) $ - LetE ("y404",[], PackedTy "Tree" "l403", - AppE "buildTree" ["l403"] [LitE 1]) $ - LetE ("z405",[], ProdTy [PackedTy "Tree" "l401", PackedTy "Tree" "l403"], + Ext $ LetLocE (Single "l401") (StartOfRegionLE (VarR "r400")) $ + LetE ("x402",[], PackedTy "Tree" (Single "l401"), + AppE "buildTree" [(Single "l401")] [LitE 2]) $ + Ext $ LetLocE (Single "l403") (AfterVariableLE "x402" (Single "l401") True) $ + LetE ("y404",[], PackedTy "Tree" (Single "l403"), + AppE "buildTree" [(Single "l403")] [LitE 1]) $ + LetE ("z405",[], ProdTy [PackedTy "Tree" (Single "l401"), PackedTy "Tree" (Single "l403")], MkProdE [VarE "x402", VarE "y404"]) $ VarE "z405" printTupProg2 :: Prog2 printTupProg2 = Prog ddtree (M.fromList [("buildTree", buildTreeFun)]) (Just (printTupMainExp2, - ProdTy [PackedTy "Tree" "l401", PackedTy "Tree" "l403"])) + ProdTy [PackedTy "Tree" (Single "l401"), PackedTy "Tree" (Single "l403")])) -------------------------------------------------------------------------------- @@ -646,73 +646,73 @@ addTreesFun = FunDef "addTrees" ["trees354"] addTreesTy addTreesBod (FunMeta Rec where addTreesTy :: ArrowTy2 Ty2 addTreesTy = ArrowTy2 - [LRM "lin351" (VarR "r350") Input, - LRM "lin352" (VarR "r351") Input, - LRM "lout353" (VarR "r754") Output] - [ProdTy [PackedTy "Tree" "lin351", PackedTy "Tree" "lin352"]] + [LRM (Single "lin351") (VarR "r350") Input, + LRM (Single "lin352") (VarR "r351") Input, + LRM (Single "lout353") (VarR "r754") Output] + [ProdTy [PackedTy "Tree" (Single "lin351"), PackedTy "Tree" (Single "lin352")]] (S.empty) - (PackedTy "Tree" "lout353") + (PackedTy "Tree" (Single "lout353")) [] False addTreesBod :: Exp2 - addTreesBod = LetE ("tree1",[],PackedTy "Tree" "lin351", + addTreesBod = LetE ("tree1",[],PackedTy "Tree" (Single "lin351"), ProjE 0 (VarE "trees354")) $ - LetE ("tree2",[],PackedTy "Tree" "lin352", + LetE ("tree2",[],PackedTy "Tree" (Single "lin352"), ProjE 1 (VarE "trees354")) $ CaseE (VarE "tree1") - [("Leaf", [("n355","l356")], + [("Leaf", [("n355",(Single "l356"))], CaseE (VarE "tree2") - [("Leaf",[("n357","l358")], + [("Leaf",[("n357",(Single "l358"))], LetE ("n358",[],IntTy,PrimAppE AddP [VarE "n355",VarE "n357"]) $ - LetE ("x359",[],PackedTy "Tree" "lout353", - DataConE "lout353" "Leaf" [VarE "n358"]) $ + LetE ("x359",[],PackedTy "Tree" (Single "lout353"), + DataConE (Single "lout353") "Leaf" [VarE "n358"]) $ VarE "x359" )] ), - ("Node", [("x360","l361"), ("y362","l363")], + ("Node", [("x360",(Single "l361")), ("y362",(Single "l363"))], CaseE (VarE "tree2") - [("Node", [("x364","l365"), ("y366","l367")], - Ext $ LetLocE "l368" (AfterConstantLE 1 "lout353") $ - LetE ("tree3",[],ProdTy [PackedTy "Tree" "l361", - PackedTy "Tree" "l365"], + [("Node", [("x364",(Single "l365")), ("y366", (Single "l367"))], + Ext $ LetLocE (Single "l368") (AfterConstantLE 1 (Single "lout353")) $ + LetE ("tree3",[],ProdTy [PackedTy "Tree" (Single "l361"), + PackedTy "Tree" (Single "l365")], MkProdE [VarE "x360", VarE "x364"]) $ - LetE ("x369",[],PackedTy "Tree" "l368", - AppE "addTrees" ["l361","l365","l368"] [VarE "tree3"]) $ - Ext $ LetLocE "l370" (AfterVariableLE "x369" "l368" True) $ - LetE ("tree4",[],ProdTy [PackedTy "Tree" "l363", - PackedTy "Tree" "l367"], + LetE ("x369",[],PackedTy "Tree" (Single "l368"), + AppE "addTrees" [(Single "l361"),(Single "l365"),(Single "l368")] [VarE "tree3"]) $ + Ext $ LetLocE (Single "l370") (AfterVariableLE "x369" (Single "l368") True) $ + LetE ("tree4",[],ProdTy [PackedTy "Tree" (Single "l363"), + PackedTy "Tree" (Single "l367")], MkProdE [VarE "y362", VarE "y366"]) $ - LetE ("y371",[],PackedTy "Tree" "l370", - AppE "addTrees" ["l363","l367","l370"] [VarE "tree4"]) $ - LetE ("z372",[],PackedTy "Tree" "lout353", - DataConE "lout353" "Node" [VarE "x369", VarE "y371"]) $ + LetE ("y371",[],PackedTy "Tree" (Single "l370"), + AppE "addTrees" [(Single "l363"),(Single "l367"),(Single "l370")] [VarE "tree4"]) $ + LetE ("z372",[],PackedTy "Tree" (Single "lout353"), + DataConE (Single "lout353") "Node" [VarE "x369", VarE "y371"]) $ VarE "z372" )] )] addTreesMainExp :: Exp2 addTreesMainExp = Ext $ LetRegionE (VarR "r400") Undefined Nothing $ - Ext $ LetLocE "l401" (StartOfRegionLE (VarR "r400")) $ - LetE ("x402",[], PackedTy "Tree" "l401", - AppE "buildTree" ["l401"] [LitE 2]) $ + Ext $ LetLocE (Single "l401") (StartOfRegionLE (VarR "r400")) $ + LetE ("x402",[], PackedTy "Tree" (Single "l401"), + AppE "buildTree" [(Single "l401")] [LitE 2]) $ -- Ext $ LetLocE "l403" (AfterVariableLE "x402" "l401" True) $ Ext $ LetRegionE (VarR "r403") Undefined Nothing $ - Ext $ LetLocE "l403" (StartOfRegionLE (VarR "r403")) $ - LetE ("y404",[], PackedTy "Tree" "l403", - AppE "buildTree" ["l403"] [LitE 2]) $ - LetE ("z405",[], ProdTy [PackedTy "Tree" "l401", PackedTy "Tree" "l403"], + Ext $ LetLocE (Single "l403") (StartOfRegionLE (VarR "r403")) $ + LetE ("y404",[], PackedTy "Tree" (Single "l403"), + AppE "buildTree" [(Single "l403")] [LitE 2]) $ + LetE ("z405",[], ProdTy [PackedTy "Tree" (Single "l401"), PackedTy "Tree" (Single "l403")], MkProdE [VarE "x402", VarE "y404"]) $ Ext $ LetRegionE (VarR "r405") Undefined Nothing $ - Ext $ LetLocE "l406" (StartOfRegionLE (VarR "r405")) $ - LetE ("a407",[],PackedTy "Tree" "l406", - AppE "addTrees" ["l401","l403","l406"] [VarE "z405"]) $ + Ext $ LetLocE (Single "l406") (StartOfRegionLE (VarR "r405")) $ + LetE ("a407",[],PackedTy "Tree" (Single "l406"), + AppE "addTrees" [(Single "l401"),(Single "l403"),(Single "l406")] [VarE "z405"]) $ VarE "a407" addTreesProg :: Prog2 addTreesProg = Prog ddtree (M.fromList [("addTrees", addTreesFun) ,("buildTree", buildTreeFun)]) - (Just (addTreesMainExp, PackedTy "Tree" "l406")) + (Just (addTreesMainExp, PackedTy "Tree" (Single "l406"))) -------------------------------------------------------------------------------- @@ -720,38 +720,38 @@ testProdFun :: FunDef2 testProdFun = FunDef "testprod" ["tup130"] testprodTy testprodBod (FunMeta Rec NoInline False) where testprodTy = ArrowTy2 - [LRM "lin131" (VarR "r132") Input, LRM "lout133" (VarR "r755") Output] - [ProdTy [(PackedTy "Tree" "lin131"), IntTy]] + [LRM (Single "lin131") (VarR "r132") Input, LRM (Single "lout133") (VarR "r755") Output] + [ProdTy [(PackedTy "Tree" (Single "lin131")), IntTy]] (S.empty) - (ProdTy [(PackedTy "Tree" "lout133"), IntTy]) + (ProdTy [(PackedTy "Tree" (Single "lout133")), IntTy]) [] False - testprodBod = LetE ("t134",[], PackedTy "Tree" "lin131", ProjE 0 (VarE "tup130")) $ + testprodBod = LetE ("t134",[], PackedTy "Tree" (Single "lin131"), ProjE 0 (VarE "tup130")) $ LetE ("i135",[], IntTy, ProjE 1 (VarE "tup130")) $ CaseE (VarE "t134") - [("Leaf",[("n136","l137")], + [("Leaf",[("n136",(Single "l137"))], LetE ("v138",[],IntTy, PrimAppE AddP [VarE "n136", LitE 1]) $ - LetE ("lf139",[],PackedTy "Tree" "lout133", - DataConE "lout133" "Leaf" [VarE "v138"]) $ - LetE ("tup148",[], ProdTy [PackedTy "Tree" "lout133", IntTy], + LetE ("lf139",[],PackedTy "Tree" (Single "lout133"), + DataConE (Single "lout133") "Leaf" [VarE "v138"]) $ + LetE ("tup148",[], ProdTy [PackedTy "Tree" (Single "lout133"), IntTy], MkProdE [VarE "lf139", VarE "i135"]) $ VarE "tup148" ), - ("Node",[("x140","l141"), ("y142","l143")], - Ext $ LetLocE "l144" (AfterConstantLE 1 "lout133") $ - LetE ("tup145",[], ProdTy [PackedTy "Tree" "l144", IntTy], - AppE "testprod" ["l141","l144"] + ("Node",[("x140",(Single "l141")), ("y142",(Single "l143"))], + Ext $ LetLocE (Single "l144") (AfterConstantLE 1 (Single "lout133")) $ + LetE ("tup145",[], ProdTy [PackedTy "Tree" (Single "l144"), IntTy], + AppE "testprod" [(Single "l141"),(Single "l144")] [MkProdE [VarE "x140", VarE "i135"]]) $ - LetE ("x149",[], PackedTy "Tree" "l144", ProjE 0 (VarE "tup145")) $ - Ext $ LetLocE "l146" (AfterVariableLE "x149" "l144" True) $ - LetE ("tup147",[], ProdTy [PackedTy "Tree" "l146", IntTy], - AppE "testprod" ["l143","l146"] + LetE ("x149",[], PackedTy "Tree" (Single "l144"), ProjE 0 (VarE "tup145")) $ + Ext $ LetLocE (Single "l146") (AfterVariableLE "x149" (Single "l144") True) $ + LetE ("tup147",[], ProdTy [PackedTy "Tree" (Single "l146"), IntTy], + AppE "testprod" [(Single "l143"),(Single "l146")] [MkProdE [VarE "y142", VarE "i135"]]) $ - LetE ("y150",[], PackedTy "Tree" "l146", ProjE 0 (VarE "tup147")) $ - LetE ("node151",[], PackedTy "Tree" "lout133", - DataConE "lout133" "Node" [VarE "x149", VarE "y150"]) $ - LetE ("tup152",[],ProdTy [PackedTy "Tree" "lout133", IntTy], + LetE ("y150",[], PackedTy "Tree" (Single "l146"), ProjE 0 (VarE "tup147")) $ + LetE ("node151",[], PackedTy "Tree" (Single "lout133"), + DataConE (Single "lout133") "Node" [VarE "x149", VarE "y150"]) $ + LetE ("tup152",[],ProdTy [PackedTy "Tree" (Single "lout133"), IntTy], MkProdE [VarE "node151", VarE "i135"]) $ VarE "tup152") ] @@ -768,8 +768,8 @@ testFlattenProg = Prog M.empty (M.fromList [("intAdd",intAddFun)]) $ Just (testF testFlattenBod :: Exp2 testFlattenBod = Ext $ LetRegionE (VarR "_") Undefined Nothing $ - Ext $ LetLocE "_" (StartOfRegionLE (VarR "_")) $ - Ext $ LetLocE "_" (AfterConstantLE 1 "_") $ + Ext $ LetLocE (Single "_") (StartOfRegionLE (VarR "_")) $ + Ext $ LetLocE (Single "_") (AfterConstantLE 1 (Single "_")) $ LetE ("v170",[],IntTy, LetE ("v171",[],IntTy, AppE "intAdd" [] @@ -789,8 +789,8 @@ stree = fromListDD [DDef (toVar "STree") [] , ("Inner",[ (False, IntTy) , (False, IntTy) -- this should be a boolean. -- for now, 1 is true, 0 is false - , (False, PackedTy "STree" "l") - , (False, PackedTy "STree" "l")]) + , (False, PackedTy "STree" (Single "l")) + , (False, PackedTy "STree" (Single "l"))]) ]] {- @@ -814,35 +814,35 @@ sumUpFun = FunDef "sumUp" ["tr1"] sumUpFunTy sumUpFunBod (FunMeta Rec NoInline F where sumUpFunTy :: ArrowTy2 Ty2 sumUpFunTy = ArrowTy2 - [LRM "lin501" (VarR "r500") Input, LRM "lout502" (VarR "r756") Output] - [PackedTy "STree" "lin501"] + [LRM (Single "lin501") (VarR "r500") Input, LRM (Single "lout502") (VarR "r756") Output] + [PackedTy "STree" (Single "lin501")] (S.empty) - (PackedTy "STree" "lout502") + (PackedTy "STree" (Single "lout502")) [] False sumUpFunBod :: Exp2 sumUpFunBod = CaseE (VarE "tr1") - [ ("Leaf", [("n503","l504")], - LetE ("x505",[],PackedTy "STree" "lout502", - DataConE "lout502" "Leaf" [VarE "n503"]) $ + [ ("Leaf", [("n503",(Single "l504"))], + LetE ("x505",[],PackedTy "STree" (Single "lout502"), + DataConE (Single "lout502") "Leaf" [VarE "n503"]) $ VarE "x505") - , ("Inner", [("i506","l507"),("b508","l509"),("x510","l511"),("y512","l513")], - Ext $ LetLocE "l514" (AfterConstantLE 1 "lout502") $ - Ext $ LetLocE "l550" (AfterVariableLE "i506" "l514" True) $ - Ext $ LetLocE "l551" (AfterVariableLE "b508" "l550" True) $ - LetE ("x515",[],PackedTy "STree" "l551", - AppE "sumUp" ["l511","l551"] [VarE "x510"]) $ - Ext $ LetLocE "l516" (AfterVariableLE "x515" "l551" True) $ - LetE ("y517",[],PackedTy "STree" "l516", - AppE "sumUp" ["l513","l516"] [VarE "y512"]) $ - LetE ("v518",[],IntTy, AppE "valueSTree" ["l551"] [VarE "x515"]) $ - LetE ("v519",[],IntTy, AppE "valueSTree" ["l516"] [VarE "y517"]) $ + , ("Inner", [("i506",(Single "l507")),("b508", (Single "l509")),("x510", (Single "l511")),("y512", (Single "l513"))], + Ext $ LetLocE (Single "l514") (AfterConstantLE 1 (Single "lout502")) $ + Ext $ LetLocE (Single "l550") (AfterVariableLE "i506" (Single "l514") True) $ + Ext $ LetLocE (Single "l551") (AfterVariableLE "b508" (Single "l550") True) $ + LetE ("x515",[],PackedTy "STree" (Single "l551"), + AppE "sumUp" [(Single "l511"),(Single "l551")] [VarE "x510"]) $ + Ext $ LetLocE (Single "l516") (AfterVariableLE "x515" (Single "l551") True) $ + LetE ("y517",[],PackedTy "STree" (Single "l516"), + AppE "sumUp" [(Single "l513"),(Single "l516")] [VarE "y512"]) $ + LetE ("v518",[],IntTy, AppE "valueSTree" [(Single "l551")] [VarE "x515"]) $ + LetE ("v519",[],IntTy, AppE "valueSTree" [(Single "l516")] [VarE "y517"]) $ LetE ("v520",[],IntTy, PrimAppE AddP [VarE "v518", VarE "v519"]) $ - LetE ("z521",[],PackedTy "STree" "lout502", - DataConE "lout502" "Inner" [VarE "v520", VarE "b508", + LetE ("z521",[],PackedTy "STree" (Single "lout502"), + DataConE (Single "lout502") "Inner" [VarE "v520", VarE "b508", VarE "x515", VarE "y517"]) $ VarE "z521" )] @@ -853,8 +853,8 @@ valueSTreeFun = FunDef "valueSTree" ["tr522"] valueSTreeFunTy valueSTreeFunBod ( where valueSTreeFunTy :: ArrowTy2 Ty2 valueSTreeFunTy = ArrowTy2 - [LRM "lin524" (VarR "r523") Input] - [PackedTy "STree" "lin524"] + [LRM (Single "lin524") (VarR "r523") Input] + [PackedTy "STree" (Single "lin524")] (S.empty) (IntTy) [] @@ -862,10 +862,10 @@ valueSTreeFun = FunDef "valueSTree" ["tr522"] valueSTreeFunTy valueSTreeFunBod ( valueSTreeFunBod :: Exp2 valueSTreeFunBod = CaseE (VarE "tr522") - [ ("Leaf", [("n523","l524")], + [ ("Leaf", [("n523",(Single "l524"))], VarE "n523") - , ("Inner", [("i525","l526"),("b527","l528"),("x529","l530"),("y531","l532")], + , ("Inner", [("i525",(Single "l526")),("b527",(Single "l528")),("x529",(Single "l530")),("y531",(Single "l532"))], VarE "i525" )] @@ -875,45 +875,45 @@ buildSTreeFun = FunDef "buildSTree" ["i543"] buildSTreeTy buildSTreeBod (FunMeta where buildSTreeTy :: ArrowTy2 Ty2 buildSTreeTy = ArrowTy2 - [LRM "lout541" (VarR "r540") Output] + [LRM (Single "lout541") (VarR "r540") Output] [IntTy] (S.empty) - (PackedTy "STree" "lout541") + (PackedTy "STree" (Single "lout541")) [] False buildSTreeBod :: Exp2 buildSTreeBod = LetE ("b542",[], BoolTy, PrimAppE EqIntP [VarE "i543", LitE 0]) $ IfE (VarE "b542") - (DataConE "lout541" "Leaf" [LitE 1]) + (DataConE (Single "lout541") "Leaf" [LitE 1]) (LetE ("i548",[], IntTy, PrimAppE SubP [VarE "i543", LitE 1]) $ LetE ("i554",[], IntTy, LitE 0) $ LetE ("b555",[], IntTy, LitE 0) $ - Ext $ LetLocE "l544" (AfterConstantLE 1 "lout541") $ - Ext $ LetLocE "l552" (AfterVariableLE "i554" "l544" True) $ - Ext $ LetLocE "l553" (AfterVariableLE "b555" "l552" True) $ - LetE ("x545",[],PackedTy "STree" "l553", - AppE "buildSTree" ["l553"] [VarE "i548"]) $ - Ext $ LetLocE "l545" (AfterVariableLE "x545" "l553" True) $ - LetE ("y546",[],PackedTy "STree" "l545", - AppE "buildSTree" ["l545"] [VarE "i548"]) $ - LetE ("a547",[],PackedTy "STree" "lout541", - DataConE "lout541" "Inner" [VarE "i554", VarE "b555", + Ext $ LetLocE (Single "l544") (AfterConstantLE 1 (Single "lout541")) $ + Ext $ LetLocE (Single "l552") (AfterVariableLE "i554" (Single "l544") True) $ + Ext $ LetLocE (Single "l553") (AfterVariableLE "b555" (Single "l552") True) $ + LetE ("x545",[],PackedTy "STree" (Single "l553"), + AppE "buildSTree" [(Single "l553")] [VarE "i548"]) $ + Ext $ LetLocE (Single "l545") (AfterVariableLE "x545" (Single "l553") True) $ + LetE ("y546",[],PackedTy "STree" (Single "l545"), + AppE "buildSTree" [(Single "l545")] [VarE "i548"]) $ + LetE ("a547",[],PackedTy "STree" (Single "lout541"), + DataConE (Single "lout541") "Inner" [VarE "i554", VarE "b555", VarE "x545", VarE "y546"]) $ VarE "a547") buildSTreeMainExp :: Exp2 buildSTreeMainExp = Ext $ LetRegionE (VarR "r530") Undefined Nothing $ - Ext $ LetLocE "l531" (StartOfRegionLE (VarR "r530")) $ - LetE ("x532",[], PackedTy "STree" "l531", - AppE "buildSTree" ["l531"] [LitE 3]) $ + Ext $ LetLocE (Single "l531") (StartOfRegionLE (VarR "r530")) $ + LetE ("x532",[], PackedTy "STree" (Single "l531"), + AppE "buildSTree" [(Single "l531")] [LitE 3]) $ VarE "x532" buildSTreeProg :: Prog2 buildSTreeProg = Prog stree (M.fromList [("buildSTree", buildSTreeFun)]) - (Just (buildSTreeMainExp, PackedTy "STree" "l531")) + (Just (buildSTreeMainExp, PackedTy "STree" (Single "l531"))) -------------------------------------------------------------------------------- @@ -923,8 +923,8 @@ sumSTreeFun = FunDef "sumSTree" ["tr762"] sumSTreeTy sumSTreeBod (FunMeta Rec No where sumSTreeTy :: ArrowTy2 Ty2 sumSTreeTy = ArrowTy2 - [LRM "lin761" (VarR "r760") Input] - [PackedTy "STree" "lin761"] + [LRM (Single "lin761") (VarR "r760") Input] + [PackedTy "STree" (Single "lin761")] (S.empty) (IntTy) [] @@ -932,14 +932,14 @@ sumSTreeFun = FunDef "sumSTree" ["tr762"] sumSTreeTy sumSTreeBod (FunMeta Rec No sumSTreeBod :: Exp2 sumSTreeBod = CaseE (VarE "tr762") - [ ("Leaf", [("n763", "l764")], + [ ("Leaf", [("n763", (Single "l764"))], VarE "n763") - , ("Inner", [("i775","l776"),("b777","l778"), - ("x764","l765"), ("y766","l767")], + , ("Inner", [("i775", (Single "l776")),("b777", (Single "l778")), + ("x764", (Single "l765")), ("y766", (Single "l767"))], LetE ("sx768", [], IntTy, - AppE "sumSTree" ["l765"] [VarE "x764"]) $ + AppE "sumSTree" [(Single "l765")] [VarE "x764"]) $ LetE ("sy769", [], IntTy, - AppE "sumSTree" ["l767"] [VarE "y766"]) $ + AppE "sumSTree" [(Single "l767")] [VarE "y766"]) $ LetE ("total770", [], IntTy , PrimAppE AddP [VarE "sx768", VarE "sy769"]) $ VarE "total770" @@ -947,11 +947,11 @@ sumSTreeFun = FunDef "sumSTree" ["tr762"] sumSTreeTy sumSTreeBod (FunMeta Rec No sumSTreeMainExp :: Exp2 sumSTreeMainExp = Ext $ LetRegionE (VarR "r771") Undefined Nothing $ - Ext $ LetLocE "l772" (StartOfRegionLE (VarR "r771")) $ - LetE ("tr773", [], PackedTy "STree" "l772", - AppE "buildSTree" ["l772"] [LitE 3]) $ + Ext $ LetLocE (Single "l772") (StartOfRegionLE (VarR "r771")) $ + LetE ("tr773", [], PackedTy "STree" (Single "l772"), + AppE "buildSTree" [(Single "l772")] [LitE 3]) $ LetE ("sum774", [], IntTy, - AppE "sumSTree" ["l772"] [VarE "tr773"]) $ + AppE "sumSTree" [(Single "l772")] [VarE "tr773"]) $ VarE "sum774" sumSTreeProg :: Prog2 @@ -963,13 +963,13 @@ sumSTreeProg = Prog stree (M.fromList [("buildSTree", buildSTreeFun), sumUpMainExp :: Exp2 sumUpMainExp = Ext $ LetRegionE (VarR "r530") Undefined Nothing $ - Ext $ LetLocE "l531" (StartOfRegionLE (VarR "r530")) $ - LetE ("x532",[], PackedTy "STree" "l531", - AppE "buildSTree" ["l531"] [LitE 2]) $ + Ext $ LetLocE (Single "l531") (StartOfRegionLE (VarR "r530")) $ + LetE ("x532",[], PackedTy "STree" (Single "l531"), + AppE "buildSTree" [(Single "l531")] [LitE 2]) $ Ext $ LetRegionE (VarR "r536") Undefined Nothing $ - Ext $ LetLocE "l537" (StartOfRegionLE (VarR "r536")) $ - LetE ("z538",[],PackedTy "STree" "l537", - AppE "sumUp" ["l531","l537"] [VarE "x532"]) $ + Ext $ LetLocE (Single "l537") (StartOfRegionLE (VarR "r536")) $ + LetE ("z538",[],PackedTy "STree" (Single "l537"), + AppE "sumUp" [(Single "l531"),(Single "l537")] [VarE "x532"]) $ VarE "z538" sumUpProg :: Prog2 @@ -977,7 +977,7 @@ sumUpProg = Prog stree (M.fromList [("sumUp", sumUpFun) ,("valueSTree", valueSTreeFun) ,("buildSTree", buildSTreeFun) ]) - (Just (sumUpMainExp, PackedTy "STree" "l537")) + (Just (sumUpMainExp, PackedTy "STree" (Single "l537"))) -------------------------------------------------------------------------------- @@ -1022,36 +1022,36 @@ setEvenFun = FunDef "setEven" ["tr570"] setEvenFunTy setEvenFunBod (FunMeta Rec where setEvenFunTy :: ArrowTy2 Ty2 setEvenFunTy = ArrowTy2 - [LRM "lin571" (VarR "r570") Input, LRM "lout572" (VarR "r757") Output] - [PackedTy "STree" "lin571"] + [LRM (Single "lin571") (VarR "r570") Input, LRM (Single "lout572") (VarR "r757") Output] + [PackedTy "STree" (Single "lin571")] (S.empty) - (PackedTy "STree" "lout572") + (PackedTy "STree" (Single "lout572")) [] False setEvenFunBod :: Exp2 setEvenFunBod = CaseE (VarE "tr570") - [ ("Leaf", [("n573","l574")], - LetE ("x575",[],PackedTy "STree" "lout572", - DataConE "lout572" "Leaf" [VarE "n573"]) $ + [ ("Leaf", [("n573",(Single "l574"))], + LetE ("x575",[],PackedTy "STree" (Single "lout572"), + DataConE (Single "lout572") "Leaf" [VarE "n573"]) $ VarE "x575") - , ("Inner", [("i576","l577"),("b578","l579"),("x580","l581"),("y582","l583")], - Ext $ LetLocE "l584" (AfterConstantLE 1 "lout572") $ - Ext $ LetLocE "l585" (AfterVariableLE "i576" "l584" True) $ - Ext $ LetLocE "l586" (AfterVariableLE "b578" "l585" True) $ - LetE ("x587",[],PackedTy "STree" "l586", - AppE "setEven" ["l581","l586"] [VarE "x580"]) $ - Ext $ LetLocE "l588" (AfterVariableLE "x587" "l586" True) $ - LetE ("y589",[],PackedTy "STree" "l588", - AppE "setEven" ["l583","l588"] [VarE "y582"]) $ - LetE ("v590",[],IntTy, AppE "valueSTree" ["l586"] [VarE "x587"]) $ - LetE ("v591",[],IntTy, AppE "valueSTree" ["l588"] [VarE "y589"]) $ + , ("Inner", [("i576",(Single "l577")),("b578",(Single "l579")),("x580",(Single "l581")),("y582",(Single "l583"))], + Ext $ LetLocE (Single "l584") (AfterConstantLE 1 (Single "lout572")) $ + Ext $ LetLocE (Single "l585") (AfterVariableLE "i576" (Single "l584") True) $ + Ext $ LetLocE (Single "l586") (AfterVariableLE "b578" (Single "l585") True) $ + LetE ("x587",[],PackedTy "STree" (Single "l586"), + AppE "setEven" [(Single "l581"),(Single "l586")] [VarE "x580"]) $ + Ext $ LetLocE (Single "l588") (AfterVariableLE "x587" (Single "l586") True) $ + LetE ("y589",[],PackedTy "STree" (Single "l588"), + AppE "setEven" [(Single "l583"),(Single "l588")] [VarE "y582"]) $ + LetE ("v590",[],IntTy, AppE "valueSTree" [(Single "l586")] [VarE "x587"]) $ + LetE ("v591",[],IntTy, AppE "valueSTree" [(Single "l588")] [VarE "y589"]) $ LetE ("v592",[],IntTy, PrimAppE AddP [VarE "v590", VarE "v591"]) $ LetE ("b593",[],IntTy, AppE "even" [] [VarE "v592"]) $ - LetE ("z594",[],PackedTy "STree" "lout572", - DataConE "lout572" "Inner" [VarE "i576", VarE "b593", + LetE ("z594",[],PackedTy "STree" (Single "lout572"), + DataConE (Single "lout572") "Inner" [VarE "i576", VarE "b593", VarE "x587", VarE "y589"]) $ VarE "z594" )] @@ -1059,13 +1059,13 @@ setEvenFun = FunDef "setEven" ["tr570"] setEvenFunTy setEvenFunBod (FunMeta Rec setEvenMainExp :: Exp2 setEvenMainExp = Ext $ LetRegionE (VarR "r592") Undefined Nothing $ - Ext $ LetLocE "l593" (StartOfRegionLE (VarR "r592")) $ - LetE ("x594",[], PackedTy "STree" "l593", - AppE "buildSTree" ["l593"] [LitE 2]) $ + Ext $ LetLocE (Single "l593") (StartOfRegionLE (VarR "r592")) $ + LetE ("x594",[], PackedTy "STree" (Single "l593"), + AppE "buildSTree" [(Single "l593")] [LitE 2]) $ Ext $ LetRegionE (VarR "r595") Undefined Nothing $ - Ext $ LetLocE "l596" (StartOfRegionLE (VarR "r595")) $ - LetE ("z597",[],PackedTy "STree" "l596", - AppE "setEven" ["l593","l596"] [VarE "x594"]) $ + Ext $ LetLocE (Single "l596") (StartOfRegionLE (VarR "r595")) $ + LetE ("z597",[],PackedTy "STree" (Single "l596"), + AppE "setEven" [(Single "l593"),(Single "l596")] [VarE "x594"]) $ VarE "z597" @@ -1075,7 +1075,7 @@ setEvenProg = Prog stree (M.fromList [("setEven" , setEvenFun) ,("buildSTree", buildSTreeFun) ,("valueSTree", valueSTreeFun) ]) - (Just (setEvenMainExp, PackedTy "STree" "l596")) + (Just (setEvenMainExp, PackedTy "STree" (Single "l596"))) -------------------------------------------------------------------------------- @@ -1105,42 +1105,42 @@ sumUpSetEvenFun = FunDef "sumUpSetEven" ["tr600"] sumUpSetEvenFunTy sumUpSetEven where sumUpSetEvenFunTy :: ArrowTy2 Ty2 sumUpSetEvenFunTy = ArrowTy2 - [LRM "lin601" (VarR "r600") Input, LRM "lout602" (VarR "r758") Output] - [PackedTy "STree" "lin601"] + [LRM (Single "lin601") (VarR "r600") Input, LRM (Single "lout602") (VarR "r758") Output] + [PackedTy "STree" (Single "lin601")] (S.empty) - (ProdTy [PackedTy "STree" "lout602", IntTy]) + (ProdTy [PackedTy "STree" (Single "lout602"), IntTy]) [] False sumUpSetEvenFunBod :: Exp2 sumUpSetEvenFunBod = CaseE (VarE "tr600") - [ ("Leaf", [("n603","l604")], - LetE ("x605",[],PackedTy "STree" "lout602", - DataConE "lout602" "Leaf" [VarE "n603"]) $ - LetE ("tx606",[], ProdTy [PackedTy "STree" "lout602", IntTy], + [ ("Leaf", [("n603",(Single "l604"))], + LetE ("x605",[],PackedTy "STree" (Single "lout602"), + DataConE (Single "lout602") "Leaf" [VarE "n603"]) $ + LetE ("tx606",[], ProdTy [PackedTy "STree" (Single "lout602"), IntTy], MkProdE [VarE "x605", VarE "n603"]) $ VarE "tx606") - , ("Inner", [("i607","l608"),("b609","l610"),("x611","l612"),("y613","l622")], - Ext $ LetLocE "l614" (AfterConstantLE 1 "lout602") $ - Ext $ LetLocE "l615" (AfterVariableLE "i607" "l614" True) $ - Ext $ LetLocE "l616" (AfterVariableLE "b609" "l615" True) $ - LetE ("tx617",[], ProdTy [PackedTy "STree" "l616", IntTy], - AppE "sumUpSetEven" ["l612","l616"] [VarE "x611"]) $ - LetE ("x618",[],PackedTy "STree" "l616", ProjE 0 (VarE "tx617")) $ + , ("Inner", [("i607",(Single "l608")),("b609", (Single "l610")),("x611", (Single "l612")),("y613", (Single "l622"))], + Ext $ LetLocE (Single "l614") (AfterConstantLE 1 (Single "lout602")) $ + Ext $ LetLocE (Single "l615") (AfterVariableLE "i607" (Single "l614") True) $ + Ext $ LetLocE (Single "l616") (AfterVariableLE "b609" (Single "l615") True) $ + LetE ("tx617",[], ProdTy [PackedTy "STree" (Single "l616"), IntTy], + AppE "sumUpSetEven" [(Single "l612"),(Single "l616")] [VarE "x611"]) $ + LetE ("x618",[],PackedTy "STree" (Single "l616"), ProjE 0 (VarE "tx617")) $ LetE ("v619",[],IntTy, ProjE 1 (VarE "tx617")) $ - Ext $ LetLocE "l620" (AfterVariableLE "x618" "l616" True) $ - LetE ("tx621",[],ProdTy [PackedTy "STree" "l620", IntTy], - AppE "sumUpSetEven" ["l622","l620"] [VarE "y613"]) $ - LetE ("y623",[],PackedTy "STree" "l620", ProjE 0 (VarE "tx621")) $ + Ext $ LetLocE (Single "l620") (AfterVariableLE "x618" (Single "l616") True) $ + LetE ("tx621",[],ProdTy [PackedTy "STree" (Single "l620"), IntTy], + AppE "sumUpSetEven" [(Single "l622"),(Single "l620")] [VarE "y613"]) $ + LetE ("y623",[],PackedTy "STree" (Single "l620"), ProjE 0 (VarE "tx621")) $ LetE ("v624",[],IntTy, ProjE 1 (VarE "tx621")) $ LetE ("v625",[],IntTy, PrimAppE AddP [VarE "v619", VarE "v624"]) $ LetE ("b626",[],IntTy, AppE "even" [] [VarE "v625"]) $ - LetE ("z627",[],PackedTy "STree" "lout602", - DataConE "lout602" "Inner" [VarE "v625", VarE "b626", + LetE ("z627",[],PackedTy "STree" (Single "lout602"), + DataConE (Single "lout602") "Inner" [VarE "v625", VarE "b626", VarE "x618", VarE "y623"]) $ - LetE ("tx638",[], ProdTy [PackedTy "STree" "lout602", IntTy], + LetE ("tx638",[], ProdTy [PackedTy "STree" (Single "lout602"), IntTy], MkProdE [VarE "z627", VarE "v625"]) $ VarE "tx638") ] @@ -1148,13 +1148,13 @@ sumUpSetEvenFun = FunDef "sumUpSetEven" ["tr600"] sumUpSetEvenFunTy sumUpSetEven sumUpSetEvenExp :: Exp2 sumUpSetEvenExp = Ext $ LetRegionE (VarR "r628") Undefined Nothing $ - Ext $ LetLocE "l629" (StartOfRegionLE (VarR "r628")) $ - LetE ("z630",[], PackedTy "STree" "l629", - AppE "buildSTree" ["l629"] [LitE 3]) $ + Ext $ LetLocE (Single "l629") (StartOfRegionLE (VarR "r628")) $ + LetE ("z630",[], PackedTy "STree" (Single "l629"), + AppE "buildSTree" [(Single "l629")] [LitE 3]) $ Ext $ LetRegionE (VarR "r631") Undefined Nothing $ - Ext $ LetLocE "l632" (StartOfRegionLE (VarR "r631")) $ - LetE ("z633",[],ProdTy [PackedTy "STree" "l632", IntTy], - AppE "sumUpSetEven" ["l629","l632"] [VarE "z630"]) $ + Ext $ LetLocE (Single "l632") (StartOfRegionLE (VarR "r631")) $ + LetE ("z633",[],ProdTy [PackedTy "STree" (Single "l632"), IntTy], + AppE "sumUpSetEven" [(Single "l629"),(Single "l632")] [VarE "z630"]) $ VarE "z633" @@ -1163,7 +1163,7 @@ sumUpSetEvenProg = Prog stree (M.fromList [("sumUpSetEven", sumUpSetEvenFun) ,("even" , evenFun ) ,("buildSTree" , buildSTreeFun) ]) - (Just (sumUpSetEvenExp, ProdTy [PackedTy "STree" "l632", IntTy])) + (Just (sumUpSetEvenExp, ProdTy [PackedTy "STree" (Single "l632"), IntTy])) -------------------------------------------------------------------------------- @@ -1189,8 +1189,8 @@ ddexpr = fromListDD [DDef (toVar "Expr") [] [ ("VARREF", [(False,IntTy)]) , ("INTLIT", [(False,IntTy)]) , ("LETE" , [(False,IntTy), - (False,PackedTy "Expr" "l"), - (False,PackedTy "Expr" "l")]) + (False,PackedTy "Expr" (Single "l")), + (False,PackedTy "Expr" (Single "l"))]) ]] copyExprFun :: FunDef2 @@ -1198,29 +1198,29 @@ copyExprFun = FunDef "copyExpr" ["e700"] copyExprFunTy copyExprFunBod (FunMeta R where copyExprFunTy :: ArrowTy2 Ty2 copyExprFunTy = ArrowTy2 - [LRM "lin702" (VarR "r701") Input, - LRM "lout703" (VarR "r759") Output] - [PackedTy "Expr" "lin702"] + [LRM (Single "lin702") (VarR "r701") Input, + LRM (Single "lout703") (VarR "r759") Output] + [PackedTy "Expr" (Single "lin702")] (S.empty) - (PackedTy "Expr" "lout703") + (PackedTy "Expr" (Single "lout703")) [] False copyExprFunBod :: Exp2 copyExprFunBod = CaseE (VarE "e700") - [ ("VARREF", [("v704","l705")], - DataConE "lout703" "VARREF" [VarE "v704"] + [ ("VARREF", [("v704",(Single "l705"))], + DataConE (Single "lout703") "VARREF" [VarE "v704"] ) - , ("LETE", [("v706","l707"), ("rhs708", "l709"), ("bod710", "l711")], - Ext $ LetLocE "l712" (AfterConstantLE 1 "lout703") $ - Ext $ LetLocE "l713" (AfterVariableLE "v706" "l712" True) $ - LetE ("rhs714",[], PackedTy "Expr" "l713", - AppE "copyExpr" ["l709","l713"] [VarE "rhs708"]) $ - Ext $ LetLocE "l715" (AfterVariableLE "rhs714" "l713" True) $ - LetE ("bod716",[],PackedTy "Expr" "l715", - AppE "copyExpr" ["l711", "l715"] [VarE "bod710"]) $ - LetE ("z717",[],PackedTy "Expr" "lout703", - DataConE "lout703" "LETE" [VarE "v706", VarE "rhs714", VarE "bod716"]) $ + , ("LETE", [("v706",(Single "l707")), ("rhs708", (Single "l709")), ("bod710", (Single "l711"))], + Ext $ LetLocE (Single "l712") (AfterConstantLE 1 (Single "lout703")) $ + Ext $ LetLocE (Single "l713") (AfterVariableLE "v706" (Single "l712") True) $ + LetE ("rhs714",[], PackedTy "Expr" (Single "l713"), + AppE "copyExpr" [(Single "l709"),(Single "l713")] [VarE "rhs708"]) $ + Ext $ LetLocE (Single "l715") (AfterVariableLE "rhs714" (Single "l713") True) $ + LetE ("bod716",[],PackedTy "Expr" (Single "l715"), + AppE "copyExpr" [(Single "l711"), (Single "l715")] [VarE "bod710"]) $ + LetE ("z717",[],PackedTy "Expr" (Single "lout703"), + DataConE (Single "lout703") "LETE" [VarE "v706", VarE "rhs714", VarE "bod716"]) $ VarE "z717") ] @@ -1230,45 +1230,45 @@ substFun = FunDef "subst" ["tr653"] substFunTy substFunBod (FunMeta Rec NoInline where substFunTy :: ArrowTy2 Ty2 substFunTy = ArrowTy2 - [LRM "lin651" (VarR "r650") Input, - LRM "lin652" (VarR "r650") Input, - LRM "lout653" (VarR "r760") Output] + [LRM (Single "lin651") (VarR "r650") Input, + LRM (Single "lin652") (VarR "r650") Input, + LRM (Single "lout653") (VarR "r760") Output] [ProdTy [IntTy, - PackedTy "Expr" "lin651", - PackedTy "Expr" "lin652"]] + PackedTy "Expr" (Single "lin651"), + PackedTy "Expr" (Single "lin652")]] (S.empty) - (PackedTy "Expr" "lout653") + (PackedTy "Expr" (Single "lout653")) [] False substFunBod :: Exp2 substFunBod = LetE ("old654",[],IntTy, ProjE 0 (VarE "tr653")) $ - LetE ("new655",[],PackedTy "Expr" "lin651", + LetE ("new655",[],PackedTy "Expr" (Single "lin651"), ProjE 1 (VarE "tr653")) $ - LetE ("expr656",[],PackedTy "Expr" "lin652", + LetE ("expr656",[],PackedTy "Expr" (Single "lin652"), ProjE 2 (VarE "tr653")) $ CaseE (VarE "expr656") - [ ("VARREF", [("v657","l658")], + [ ("VARREF", [("v657",(Single "l658"))], LetE ("b659",[], BoolTy, PrimAppE EqIntP [VarE "v657", VarE "old654"]) $ IfE (VarE "b659") - (AppE "copyExpr" ["lin651", "lout653"] [VarE "new655"]) - (DataConE "lout653" "VARREF" [VarE "v657"])) - , ("LETE", [("v656","l657"), ("rhs658","l659"), ("bod660", "l661")], + (AppE "copyExpr" [(Single "lin651"), (Single "lout653")] [VarE "new655"]) + (DataConE (Single "lout653") "VARREF" [VarE "v657"])) + , ("LETE", [("v656",(Single "l657")), ("rhs658",(Single "l659")), ("bod660", (Single "l661"))], LetE ("b662",[],BoolTy, PrimAppE EqIntP [VarE "v656", VarE "old654"]) -- IfE (VarE "b662") - (Ext $ LetLocE "l663" (AfterConstantLE 1 "lout653") $ - Ext $ LetLocE "l664" (AfterVariableLE "v656" "l663" True) $ - LetE ("p668",[], ProdTy [IntTy, PackedTy "Expr" "lin651", PackedTy "Expr" "l659"], + (Ext $ LetLocE (Single "l663") (AfterConstantLE 1 (Single "lout653")) $ + Ext $ LetLocE (Single "l664") (AfterVariableLE "v656" (Single "l663") True) $ + LetE ("p668",[], ProdTy [IntTy, PackedTy "Expr" (Single "lin651"), PackedTy "Expr" (Single "l659")], MkProdE [VarE "old654", VarE "new655", VarE "rhs658"]) $ - LetE ("rhs665",[],PackedTy "Expr" "l664", - AppE "subst" ["lin651", "l659", "l664"] [VarE "p668"]) $ - Ext $ LetLocE "l669" (AfterVariableLE "rhs665" "l664" True) $ - LetE ("bod670",[], PackedTy "Expr" "l669", - AppE "copyExpr" ["l661", "l669"] [VarE "bod660"]) $ - LetE ("z671",[], PackedTy "Expr" "lout653", - DataConE "lout653" "LETE" [VarE "v656", VarE "rhs665", VarE "bod670"]) $ + LetE ("rhs665",[],PackedTy "Expr" (Single "l664"), + AppE "subst" [(Single "lin651"), (Single "l659"), (Single "l664")] [VarE "p668"]) $ + Ext $ LetLocE (Single "l669") (AfterVariableLE "rhs665" (Single "l664") True) $ + LetE ("bod670",[], PackedTy "Expr" (Single "l669"), + AppE "copyExpr" [(Single "l661"), (Single "l669")] [VarE "bod660"]) $ + LetE ("z671",[], PackedTy "Expr" (Single "lout653"), + DataConE (Single "lout653") "LETE" [VarE "v656", VarE "rhs665", VarE "bod670"]) $ VarE "z671") ) ] @@ -1276,44 +1276,44 @@ substFun = FunDef "subst" ["tr653"] substFunTy substFunBod (FunMeta Rec NoInline substMainExp :: Exp2 substMainExp = Ext $ LetRegionE (VarR "r720") Undefined Nothing $ - Ext $ LetLocE "l721" (StartOfRegionLE (VarR "r720")) $ - Ext $ LetLocE "l722" (AfterConstantLE 1 "l721") $ - Ext $ LetLocE "l723" (AfterConstantLE 8 "l722") $ - LetE ("rhs724",[], PackedTy "Expr" "l723", - DataConE "l723" "VARREF" [LitE 1]) $ - Ext $ LetLocE "l724" (AfterVariableLE "rhs724" "l723" True) $ - LetE ("bod725",[], PackedTy "Expr" "l724", - DataConE "l724" "VARREF" [LitE 10]) $ + Ext $ LetLocE (Single "l721") (StartOfRegionLE (VarR "r720")) $ + Ext $ LetLocE (Single "l722") (AfterConstantLE 1 (Single "l721")) $ + Ext $ LetLocE (Single "l723") (AfterConstantLE 8 (Single "l722")) $ + LetE ("rhs724",[], PackedTy "Expr" (Single "l723"), + DataConE (Single "l723") "VARREF" [LitE 1]) $ + Ext $ LetLocE (Single "l724") (AfterVariableLE "rhs724" (Single "l723") True) $ + LetE ("bod725",[], PackedTy "Expr" (Single "l724"), + DataConE (Single "l724") "VARREF" [LitE 10]) $ LetE ("old726",[],IntTy,LitE 1) $ - LetE ("z727",[], PackedTy "Expr" "l721", - DataConE "l721" "LETE" [VarE "old726", VarE "rhs724", VarE "bod725"]) $ + LetE ("z727",[], PackedTy "Expr" (Single "l721"), + DataConE (Single "l721") "LETE" [VarE "old726", VarE "rhs724", VarE "bod725"]) $ Ext $ LetRegionE (VarR "r728") Undefined Nothing $ - Ext $ LetLocE "l729" (StartOfRegionLE (VarR "r728")) $ - LetE ("new730",[],PackedTy "Expr" "l729", - DataConE "l729" "VARREF" [LitE 42]) $ - LetE ("p731",[],ProdTy [IntTy, PackedTy "Expr" "l729", PackedTy "Expr" "l721"], + Ext $ LetLocE (Single "l729") (StartOfRegionLE (VarR "r728")) $ + LetE ("new730",[],PackedTy "Expr" (Single "l729"), + DataConE (Single "l729") "VARREF" [LitE 42]) $ + LetE ("p731",[],ProdTy [IntTy, PackedTy "Expr" (Single "l729"), PackedTy "Expr" (Single "l721")], MkProdE [VarE "old726", VarE "new730", VarE "z727"]) $ - Ext $ LetLocE "l730" (AfterVariableLE "new730" "l729" True) $ - LetE ("z732",[], PackedTy "Expr" "l730", - AppE "subst" ["l729", "l721", "l730"] [VarE "p731"]) $ + Ext $ LetLocE (Single "l730") (AfterVariableLE "new730" (Single "l729") True) $ + LetE ("z732",[], PackedTy "Expr" (Single "l730"), + AppE "subst" [(Single "l729"), (Single "l721"), (Single "l730")] [VarE "p731"]) $ VarE "z732" substProg :: Prog2 substProg = Prog ddexpr (M.fromList [("subst", substFun), ("copyExpr", copyExprFun)]) - (Just (substMainExp, PackedTy "Expr" "l730")) + (Just (substMainExp, PackedTy "Expr" (Single "l730"))) -------------------------------------------------------------------------------- ddtree' :: DDefs Ty2 ddtree' = fromListDD [DDef (toVar "Tree") [] [ ("Leaf",[(False,IntTy)]) - , ("Node",[ (False,PackedTy "Tree" "l") - , (False,PackedTy "Tree" "l")]) + , ("Node",[ (False,PackedTy "Tree" (Single "l")) + , (False,PackedTy "Tree" (Single "l"))]) , ("Node^", [ (False,CursorTy) - , (False,PackedTy "Tree" "l") - , (False,PackedTy "Tree" "l")]) + , (False,PackedTy "Tree" (Single "l")) + , (False,PackedTy "Tree" (Single "l"))]) , (indirectionTag++"1", [(False,CursorTy)]) ]] @@ -1325,44 +1325,44 @@ indrBuildTreeFun = FunDef "indrBuildTree" ["i270"] indrBuildTreeTy indrBuildTree where indrBuildTreeTy :: ArrowTy2 Ty2 indrBuildTreeTy = ArrowTy2 - [LRM "lout272" (VarR "r271") Output] + [LRM (Single "lout272") (VarR "r271") Output] [IntTy] (S.empty) - (PackedTy "Tree" "lout272") + (PackedTy "Tree" (Single "lout272")) [] False indrBuildTreeBod :: Exp2 indrBuildTreeBod = LetE ("b279",[], BoolTy, PrimAppE EqIntP [VarE "i270", LitE 0]) $ IfE (VarE "b279") - (DataConE "lout272" "Leaf" [LitE 1]) + (DataConE (Single "lout272") "Leaf" [LitE 1]) (LetE ("i273",[], IntTy, PrimAppE SubP [VarE "i270", LitE 1]) $ - Ext $ LetLocE "loc_indr" (AfterConstantLE 1 "lout272") $ - Ext $ LetLocE "l274" (AfterConstantLE 8 "loc_indr") $ - LetE ("x275",[],PackedTy "Tree" "l274", - AppE "indrBuildTree" ["l274"] [VarE "i273"]) $ - Ext $ LetLocE "l276" (AfterVariableLE "x275" "l274" True) $ - LetE ("y277",[],PackedTy "Tree" "l276", - AppE "indrBuildTree" ["l276"] [VarE "i273"]) $ + Ext $ LetLocE (Single "loc_indr") (AfterConstantLE 1 (Single "lout272")) $ + Ext $ LetLocE (Single "l274") (AfterConstantLE 8 (Single "loc_indr")) $ + LetE ("x275",[],PackedTy "Tree" (Single "l274"), + AppE "indrBuildTree" [(Single "l274")] [VarE "i273"]) $ + Ext $ LetLocE (Single "l276") (AfterVariableLE "x275" (Single "l274") True) $ + LetE ("y277",[],PackedTy "Tree" (Single "l276"), + AppE "indrBuildTree" [(Single "l276")] [VarE "i273"]) $ LetE ("indr_cur",[],CursorTy,Ext (StartOfPkdCursor "y277")) $ -- LetE ("indr_node",[], PackedTy "Tree" "loc_indr", -- DataConE "loc_indr" (indirectionTag++"1") [VarE "indr_cur"]) $ - LetE ("a278",[],PackedTy "Tree" "lout272", - DataConE "lout272" "Node^" [VarE "indr_cur", + LetE ("a278",[],PackedTy "Tree" (Single "lout272"), + DataConE (Single "lout272") "Node^" [VarE "indr_cur", VarE "x275", VarE "y277"]) $ VarE "a278") indrBuildTreeMainExp :: Exp2 indrBuildTreeMainExp = Ext $ LetRegionE (VarR "r800") Undefined Nothing $ - Ext $ LetLocE "l801" (StartOfRegionLE (VarR "r800")) $ - LetE ("tr802", [], PackedTy "Tree" "l801", - AppE "indrBuildTree" ["l801"] [LitE 3]) $ + Ext $ LetLocE (Single "l801") (StartOfRegionLE (VarR "r800")) $ + LetE ("tr802", [], PackedTy "Tree" (Single "l801"), + AppE "indrBuildTree" [(Single "l801")] [LitE 3]) $ VarE "tr802" indrBuildTreeProg :: Prog2 indrBuildTreeProg = Prog ddtree' (M.fromList [("indrBuildTree", indrBuildTreeFun)]) - (Just (indrBuildTreeMainExp, PackedTy "Tree" "l801")) + (Just (indrBuildTreeMainExp, PackedTy "Tree" (Single "l801"))) indrRightmostFun :: FunDef2 @@ -1370,8 +1370,8 @@ indrRightmostFun = FunDef "indrRightmost" ["t742"] indrRightmostTy indrRightmost where indrRightmostTy :: ArrowTy2 Ty2 indrRightmostTy = ArrowTy2 - [LRM "lin741" (VarR "r740") Input] - [PackedTy "Tree" "lin741"] + [LRM (Single "lin741") (VarR "r740") Input] + [PackedTy "Tree" (Single "lin741")] S.empty IntTy [] @@ -1379,19 +1379,19 @@ indrRightmostFun = FunDef "indrRightmost" ["t742"] indrRightmostTy indrRightmost indrRightmostBod :: Exp2 indrRightmostBod = CaseE (VarE "t742") - [("Leaf", [("n746","l747")], + [("Leaf", [("n746",(Single "l747"))], VarE "n746"), - ("Node^", [("indr_y750","lindr_y750"),("x748","l749"), ("y750","l751")], - LetE ("lm752",[],IntTy, AppE "indrRightmost" ["l751"] [VarE "y750"]) $ + ("Node^", [("indr_y750",(Single "lindr_y750")),("x748",(Single "l749")), ("y750",(Single "l751"))], + LetE ("lm752",[],IntTy, AppE "indrRightmost" [(Single "l751")] [VarE "y750"]) $ VarE "lm752")] indrRightmostMainExp :: Exp2 indrRightmostMainExp = Ext $ LetRegionE (VarR "r753") Undefined Nothing $ - Ext $ LetLocE "l754" (StartOfRegionLE (VarR "r753")) $ - LetE ("tr1", [], PackedTy "Tree" "l754", - AppE "indrBuildTree" ["l754"] [LitE 3]) $ + Ext $ LetLocE (Single "l754") (StartOfRegionLE (VarR "r753")) $ + LetE ("tr1", [], PackedTy "Tree" (Single "l754"), + AppE "indrBuildTree" [(Single "l754")] [LitE 3]) $ LetE ("a760",[], IntTy, - AppE "indrRightmost" ["l754"] [VarE "tr1"]) $ + AppE "indrRightmost" [(Single "l754")] [VarE "tr1"]) $ VarE "a760" indrRightmostProg :: Prog2 @@ -1406,19 +1406,19 @@ indrIDFun = FunDef "indrID" ["tr800"] indrIDTy indrIDBod (FunMeta NotRec NoInlin where indrIDTy :: ArrowTy2 Ty2 indrIDTy = ArrowTy2 - [LRM "lin802" (VarR "r801") Input, LRM "lout803" (VarR "r803") Output] - [PackedTy "Tree" "lin802"] + [LRM (Single "lin802") (VarR "r801") Input, LRM (Single "lout803") (VarR "r803") Output] + [PackedTy "Tree" (Single "lin802")] (S.empty) - (PackedTy "Tree" "lout803") + (PackedTy "Tree" (Single "lout803")) [] False indrIDBod :: Exp2 - indrIDBod = LetE ("a804",[], PackedTy "Tree" "lout803", + indrIDBod = LetE ("a804",[], PackedTy "Tree" (Single "lout803"), Ext $ IndirectionE "Tree" (indirectionTag++"1") - ("lout803","r803") - ("lin802", "r801") + ((Single "lout803"),(Single "r803")) + ((Single "lin802"), (Single "r801")) (LitE 10)) $ VarE "a804" @@ -1427,15 +1427,15 @@ indrIDFun = FunDef "indrID" ["tr800"] indrIDTy indrIDBod (FunMeta NotRec NoInlin indrIDMainExp :: Exp2 indrIDMainExp = Ext $ LetRegionE (VarR "r806") Undefined Nothing $ - Ext $ LetLocE "l807" (StartOfRegionLE (VarR "r806")) $ - LetE ("tr1",[], PackedTy "Tree" "l807", - AppE "indrBuildTree" ["l807"] [LitE 2]) $ + Ext $ LetLocE (Single "l807") (StartOfRegionLE (VarR "r806")) $ + LetE ("tr1",[], PackedTy "Tree" (Single "l807"), + AppE "indrBuildTree" [(Single "l807")] [LitE 2]) $ Ext $ LetRegionE (VarR "r808") Undefined Nothing $ - Ext $ LetLocE "l809" (StartOfRegionLE (VarR "r808")) $ - LetE ("tr2",[], PackedTy "Tree" "l809", - AppE "indrID" ["l807", "l809"] [VarE "tr1"]) $ + Ext $ LetLocE (Single "l809") (StartOfRegionLE (VarR "r808")) $ + LetE ("tr2",[], PackedTy "Tree" (Single "l809"), + AppE "indrID" [(Single "l807"), (Single "l809")] [VarE "tr1"]) $ LetE ("rmost",[], IntTy, - AppE "indrRightmost" ["l809"] [VarE "tr2"]) $ + AppE "indrRightmost" [(Single "l809")] [VarE "tr2"]) $ VarE "rmost" indrIDProg :: Prog2 @@ -1449,15 +1449,15 @@ indrIDProg = Prog ddtree' (M.fromList [("indrBuildTree", indrBuildTreeFun) indrIDSumMainExp :: Exp2 indrIDSumMainExp = Ext $ LetRegionE (VarR "r806") Undefined Nothing $ - Ext $ LetLocE "l807" (StartOfRegionLE (VarR "r806")) $ - LetE ("tr1",[], PackedTy "Tree" "l807", - AppE "buildTree" ["l807"] [LitE 10]) $ + Ext $ LetLocE (Single "l807") (StartOfRegionLE (VarR "r806")) $ + LetE ("tr1",[], PackedTy "Tree" (Single "l807"), + AppE "buildTree" [(Single "l807")] [LitE 10]) $ Ext $ LetRegionE (VarR "r808") Undefined Nothing $ - Ext $ LetLocE "l809" (StartOfRegionLE (VarR "r808")) $ - LetE ("tr2",[], PackedTy "Tree" "l809", - AppE "indrID" ["l807", "l809"] [VarE "tr1"]) $ + Ext $ LetLocE (Single "l809") (StartOfRegionLE (VarR "r808")) $ + LetE ("tr2",[], PackedTy "Tree" (Single "l809"), + AppE "indrID" [(Single "l807"), (Single "l809")] [VarE "tr1"]) $ LetE ("total",[], IntTy, - AppE "sumTree" ["l809"] [VarE "tr2"]) $ + AppE "sumTree" [(Single "l809")] [VarE "tr2"]) $ VarE "total" indrIDSumProg :: Prog2 @@ -1470,7 +1470,7 @@ indrIDSumProg = Prog ddtree' (M.fromList [("buildTree", buildTreeFun) ddsnoclist :: DDefs Ty2 ddsnoclist = fromListDD [DDef (toVar "SnocList") [] - [ ("Nil" , []) - , ("Snoc" , [(False,PackedTy "SnocList" "l"), + [ ("Nil", []) + , ("Snoc" , [(False,PackedTy "SnocList" (Single "l")), (False,IntTy)]) ]] diff --git a/gibbon-compiler/src/Gibbon/L2/Syntax.hs b/gibbon-compiler/src/Gibbon/L2/Syntax.hs index 974a86a54..61af8cd88 100644 --- a/gibbon-compiler/src/Gibbon/L2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L2/Syntax.hs @@ -56,6 +56,7 @@ module Gibbon.L2.Syntax , dummyTyLocs , allFreeVars , freeLocVars + , singleLocVar -- * Other helpers , revertToL1 @@ -82,11 +83,11 @@ import qualified Gibbon.L1.Syntax as L1 -------------------------------------------------------------------------------- -type Prog2 = Prog Exp2 +type Prog2 = Prog LocVar Exp2 type DDef2 = DDef Ty2 type DDefs2 = DDefs Ty2 -type FunDef2 = FunDef Exp2 -type FunDefs2 = FunDefs Exp2 +type FunDef2 = FunDef LocVar Exp2 +type FunDefs2 = FunDefs LocVar Exp2 -- | Function types know about locations and traversal effects. instance FunctionTy Ty2 where @@ -198,7 +199,6 @@ type LocExp = PreLocExp LocVar data LocRet = EndOf LRM deriving (Read, Show, Eq, Ord, Generic, NFData) - instance FreeVars (E2Ext l d) where gFreeVars e = case e of @@ -223,12 +223,11 @@ instance FreeVars (E2Ext l d) where SSPush{} -> S.empty SSPop{} -> S.empty - instance FreeVars LocExp where gFreeVars e = case e of - AfterConstantLE _ loc -> S.singleton loc - AfterVariableLE v loc _ -> S.fromList [v,loc] + AfterConstantLE _ loc -> S.singleton $ unwrapLocVar loc + AfterVariableLE v loc _ -> S.fromList $ [v, unwrapLocVar loc] _ -> S.empty instance (Out l, Out d, Show l, Show d) => Expression (E2Ext l d) where @@ -485,7 +484,7 @@ instance NFData LRM where -- | A designated doesn't-really-exist-anywhere location. dummyLRM :: LRM -dummyLRM = LRM "l_dummy" (VarR "r_dummy") Input +dummyLRM = LRM (singleLocVar "l_dummy") (VarR "r_dummy") Input regionToVar :: Region -> Var regionToVar r = case r of @@ -556,6 +555,8 @@ instance Typeable (PreExp E2Ext LocVar (UrTy LocVar)) where instance Out (ArrowTy2 Ty2) +--instance Out (ArrowTy2 Ty2SoA) + instance Out Effect instance Out a => Out (S.Set a) where docPrec n x = docPrec n (S.toList x) @@ -579,15 +580,15 @@ outLocVars ty = L.map (\(LRM l _ _) -> l) $ L.filter (\(LRM _ _ m) -> m == Output) (locVars ty) outRegVars :: ArrowTy2 ty2 -> [LocVar] -outRegVars ty = L.map (\(LRM _ r _) -> regionToVar r) $ +outRegVars ty = L.map (\(LRM _ r _) -> (singleLocVar (regionToVar r))) $ L.filter (\(LRM _ _ m) -> m == Output) (locVars ty) inRegVars :: ArrowTy2 ty2 -> [LocVar] -inRegVars ty = L.nub $ L.map (\(LRM _ r _) -> regionToVar r) $ +inRegVars ty = L.nub $ L.map (\(LRM _ r _) -> (singleLocVar (regionToVar r))) $ L.filter (\(LRM _ _ m) -> m == Input) (locVars ty) allRegVars :: ArrowTy2 ty2 -> [LocVar] -allRegVars ty = L.nub $ L.map (\(LRM _ r _) -> regionToVar r) (locVars ty) +allRegVars ty = L.nub $ L.map (\(LRM _ r _) -> (singleLocVar (regionToVar r))) (locVars ty) -- | Apply a location substitution to a type. substLoc :: M.Map LocVar LocVar -> Ty2 -> Ty2 @@ -614,7 +615,7 @@ substLocs mp tys = L.map (substLoc mp) tys -- MkFoo (i:loc1) (f:loc2) -> -- new_env2 = extendPatternMatchEnv [loc1,loc2] old_env2 extendPatternMatchEnv :: HasCallStack => DataCon -> DDefs Ty2 -> [Var] -> [LocVar] - -> Env2 Ty2 -> Env2 Ty2 + -> Env2 Var Ty2 -> Env2 Var Ty2 extendPatternMatchEnv dcon ddefs vars locs env2 = let tys = lookupDataCon ddefs dcon tys' = foldr @@ -640,7 +641,7 @@ substEffs mp effs = S.map (\ef -> substEff mp ef) effs dummyTyLocs :: Applicative f => UrTy () -> f (UrTy LocVar) -dummyTyLocs ty = traverse (const (pure (toVar "dummy"))) ty +dummyTyLocs ty = traverse (const (pure (singleLocVar (toVar "dummy")))) ty -- | Collect all the locations mentioned in a type. locsInTy :: Ty2 -> [LocVar] @@ -652,7 +653,7 @@ locsInTy ty = -- Because L2 just adds a bit of metadata and enriched types, it is -- possible to strip it back down to L1. -revertToL1 :: Prog2 -> Prog1 +revertToL1 :: Prog2 -> Prog1 revertToL1 Prog{ddefs,fundefs,mainExp} = Prog ddefs' funefs' mainExp' where @@ -671,7 +672,7 @@ revertDDef (DDef tyargs a b) = revertFunDef :: FunDef2 -> FunDef1 revertFunDef FunDef{funName,funArgs,funTy,funBody,funMeta} = FunDef { funName = funName - , funArgs = funArgs + , funArgs = (map unwrapLocVar funArgs) , funTy = (L.map stripTyLocs (arrIns funTy), stripTyLocs (arrOut funTy)) , funBody = revertExp funBody , funMeta = funMeta @@ -780,7 +781,7 @@ occurs w ex = BoundsCheck{} -> False AddFixed v _ -> v `S.member` w IndirectionE _ _ (_,v1) (_,v2) ib -> - v1 `S.member` w || v2 `S.member` w || go ib + (unwrapLocVar v1) `S.member` w || (unwrapLocVar v2) `S.member` w || go ib GetCilkWorkerNum -> False LetAvail _ bod -> go bod AllocateTagHere{} -> False @@ -792,7 +793,6 @@ occurs w ex = where go = occurs w - mapPacked :: (Var -> l -> UrTy l) -> UrTy l -> UrTy l mapPacked fn t = case t of @@ -864,7 +864,7 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty let (vars,locs) = unzip vlocs acc'' = L.foldr (\w acc''' -> M.insertWith (++) v [w] acc''') acc' - (vars ++ locs) + (vars ++ (map unwrapLocVar locs)) in go acc'' e) acc mp @@ -882,7 +882,9 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty go (M.insertWith (++) (regionToVar r) (S.toList $ allFreeVars rhs) acc) rhs LetParRegionE r _ _ rhs -> go (M.insertWith (++) (regionToVar r) (S.toList $ allFreeVars rhs) acc) rhs - LetLocE loc phs rhs -> + LetLocE (Single loc) phs rhs -> + -- Assumption that the loc for the data constructor buffer is passed in case + -- of SoA. If in SoA, ignoring the locs of the fields atm. go (M.insertWith (++) loc (dep phs ++ (S.toList $ allFreeVars rhs)) acc) rhs RetE{} -> acc FromEndE{} -> acc @@ -902,49 +904,49 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty dep ex = case ex of StartOfRegionLE r -> [regionToVar r] - AfterConstantLE _ loc -> [loc] - AfterVariableLE v loc _ -> [v,loc] + AfterConstantLE _ (Single loc) -> [loc] + AfterVariableLE v (Single loc) _ -> [v,loc] InRegionLE r -> [regionToVar r] - FromEndLE loc -> [loc] + FromEndLE (Single loc) -> [loc] FreeLE -> [] -- gFreeVars ++ locations ++ region variables allFreeVars :: Exp2 -> S.Set Var allFreeVars ex = case ex of - AppE _ locs args -> S.fromList locs `S.union` (S.unions (map allFreeVars args)) + AppE _ locs args -> S.fromList (map unwrapLocVar locs) `S.union` (S.unions (map allFreeVars args)) PrimAppE _ args -> (S.unions (map allFreeVars args)) - LetE (v,locs,_,rhs) bod -> (S.fromList locs `S.union` (allFreeVars rhs) `S.union` (allFreeVars bod)) + LetE (v,locs,_,rhs) bod -> (S.fromList (map unwrapLocVar locs) `S.union` (allFreeVars rhs) `S.union` (allFreeVars bod)) `S.difference` S.singleton v IfE a b c -> allFreeVars a `S.union` allFreeVars b `S.union` allFreeVars c MkProdE args -> (S.unions (map allFreeVars args)) ProjE _ bod -> allFreeVars bod CaseE scrt brs -> (allFreeVars scrt) `S.union` (S.unions (map (\(_,vlocs,c) -> allFreeVars c `S.difference` S.fromList (map fst vlocs) `S.difference` - S.fromList (map snd vlocs)) + S.fromList (map (unwrapLocVar . snd) vlocs)) brs)) - DataConE loc _ args -> S.singleton loc `S.union` (S.unions (map allFreeVars args)) + DataConE locvar _ args -> S.singleton (unwrapLocVar locvar) `S.union` (S.unions (map allFreeVars args)) TimeIt e _ _ -> allFreeVars e WithArenaE _ e -> allFreeVars e - SpawnE _ locs args -> S.fromList locs `S.union` (S.unions (map allFreeVars args)) + SpawnE _ locs args -> S.fromList (map unwrapLocVar locs) `S.union` (S.unions (map allFreeVars args)) Ext ext -> case ext of LetRegionE r _ _ bod -> S.delete (regionToVar r) (allFreeVars bod) LetParRegionE r _ _ bod -> S.delete (regionToVar r) (allFreeVars bod) - LetLocE loc locexp bod -> S.delete loc (allFreeVars bod `S.union` gFreeVars locexp) + LetLocE loc locexp bod -> S.difference (S.singleton $ unwrapLocVar loc) (allFreeVars bod `S.union` gFreeVars locexp) StartOfPkdCursor cur -> S.singleton cur TagCursor a b-> S.fromList [a,b] - RetE locs v -> S.insert v (S.fromList locs) - FromEndE loc -> S.singleton loc - BoundsCheck _ reg cur -> S.fromList [reg,cur] - IndirectionE _ _ (a,b) (c,d) _ -> S.fromList $ [a,b,c,d] + RetE locs v -> S.insert v (S.fromList (map unwrapLocVar locs)) + FromEndE loc -> S.singleton $ unwrapLocVar loc + BoundsCheck _ (Single reg) (Single cur) -> S.fromList [reg,cur] + IndirectionE _ _ (a, b) (c, d) _ -> S.fromList $ [(unwrapLocVar a),(unwrapLocVar b),(unwrapLocVar c), (unwrapLocVar d)] AddFixed v _ -> S.singleton v GetCilkWorkerNum-> S.empty LetAvail vs bod -> S.fromList vs `S.union` gFreeVars bod - AllocateTagHere loc _ -> S.singleton loc - AllocateScalarsHere loc -> S.singleton loc - SSPush _ a b _ -> S.fromList [a,b] - SSPop _ a b -> S.fromList [a,b] + AllocateTagHere (Single loc) _ -> S.singleton loc + AllocateScalarsHere (Single loc) -> S.singleton loc + SSPush _ (Single a) (Single b) _ -> S.fromList [a,b] + SSPop _ (Single a) (Single b) -> S.fromList [a,b] _ -> gFreeVars ex freeLocVars :: Exp2 -> [Var] diff --git a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs index fcb078ddb..9a28fd96b 100644 --- a/gibbon-compiler/src/Gibbon/L2/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L2/Typecheck.hs @@ -118,7 +118,7 @@ type TcM a = (Except TCError) a -- | Check an expression. Given the data definitions, an general type environment, a function map, -- a constraint set, a region set, an (input) location state map, and the expression, this function -- will either throw an error, or return a pair of expression type and new location state map. -tcExp :: DDefs Ty2 -> Env2 Ty2 -> FunDefs2 +tcExp :: DDefs Ty2 -> Env2 Var Ty2 -> FunDefs2 -> ConstraintSet -> RegionSet -> LocationTypeState -> Exp -> TcM (Ty2, LocationTypeState) tcExp ddfs env funs constrs regs tstatein exp = @@ -767,34 +767,33 @@ tcExp ddfs env funs constrs regs tstatein exp = regs' <- regionInsert exp r regs (ty,tstate) <- tcExp ddfs env funs constrs regs' tstatein e return (ty,tstate) - - Ext (LetLocE v c e) -> do - let env' = extendVEnv v CursorTy env + Ext (LetLocE (Single loc) c e) -> do + let env' = extendVEnv loc CursorTy env case c of StartOfRegionLE r -> do ensureRegion exp r regs absentStart exp constrs r - let tstate1 = extendTS v (Output,False) tstatein - let constrs1 = extendConstrs (StartOfC v r) $ extendConstrs (InRegionC v r) constrs + let tstate1 = extendTS (Single loc) (Output,False) tstatein + let constrs1 = extendConstrs (StartOfC (Single loc) r) $ extendConstrs (InRegionC (Single loc) r) constrs (ty,tstate2) <- tcExp ddfs env' funs constrs1 regs tstate1 e - tstate3 <- removeLoc exp tstate2 v + tstate3 <- removeLoc exp tstate2 (Single loc) return (ty,tstate3) AfterConstantLE i l1 -> do r <- getRegion exp constrs l1 - let tstate1 = extendTS v (Output,True) $ setAfter l1 tstatein - let constrs1 = extendConstrs (InRegionC v r) $ extendConstrs (AfterConstantC i l1 v) constrs + let tstate1 = extendTS (Single loc) (Output,True) $ setAfter l1 tstatein + let constrs1 = extendConstrs (InRegionC (Single loc) r) $ extendConstrs (AfterConstantC i l1 (Single loc)) constrs (ty,tstate2) <- tcExp ddfs env' funs constrs1 regs tstate1 e - tstate3 <- removeLoc exp tstate2 v + tstate3 <- removeLoc exp tstate2 (Single loc) return (ty,tstate3) AfterVariableLE x l1 _ -> do r <- getRegion exp constrs l1 (_xty,tstate1) <- tcExp ddfs env funs constrs regs tstatein $ VarE x -- NOTE: We now allow aliases (offsets) from scalar vars too. So we can leave out this check -- ensurePackedLoc exp xty l1 - let tstate2 = extendTS v (Output,True) $ setAfter l1 tstate1 - let constrs1 = extendConstrs (InRegionC v r) $ extendConstrs (AfterVariableC x l1 v) constrs + let tstate2 = extendTS (Single loc) (Output,True) $ setAfter l1 tstate1 + let constrs1 = extendConstrs (InRegionC (Single loc) r) $ extendConstrs (AfterVariableC x l1 (Single loc)) constrs (ty,tstate3) <- tcExp ddfs env' funs constrs1 regs tstate2 e - tstate4 <- removeLoc exp tstate3 v + tstate4 <- removeLoc exp tstate3 (Single loc) return (ty,tstate4) FromEndLE _l1 -> do -- TODO: This is the bare minimum which gets the examples typechecking again. @@ -802,7 +801,7 @@ tcExp ddfs env funs constrs regs tstatein exp = (ty,tstate1) <- tcExp ddfs env' funs constrs regs tstatein e return (ty,tstate1) FreeLE -> - do let constrs1 = extendConstrs (InRegionC v globalReg) $ constrs + do let constrs1 = extendConstrs (InRegionC (Single loc) globalReg) $ constrs (ty,tstate1) <- tcExp ddfs env' funs constrs1 regs tstatein e return (ty,tstate1) @@ -865,7 +864,7 @@ tcExp ddfs env funs constrs regs tstatein exp = -- | Helper function to check case branches. -tcCases :: DDefs Ty2 -> Env2 Ty2 -> FunDefs2 +tcCases :: DDefs Ty2 -> Env2 Var Ty2 -> FunDefs2 -> ConstraintSet -> RegionSet -> LocationTypeState -> LocVar -> Region -> [(DataCon, [(Var,LocVar)], Exp)] -> TcM ([Ty2], LocationTypeState) @@ -920,7 +919,7 @@ tcProj e _i ty = throwError $ GenericTC ("Projection from non-tuple type " ++ (s -- the order matters because the location state map is threaded through, -- so this is assuming the list of expressions would have been evaluated -- in first-to-last order. -tcExps :: DDefs Ty2 -> Env2 Ty2 -> FunDefs2 +tcExps :: DDefs Ty2 -> Env2 Var Ty2 -> FunDefs2 -> ConstraintSet -> RegionSet -> LocationTypeState -> [Exp] -> TcM ([Ty2], LocationTypeState) tcExps ddfs env funs constrs regs tstatein (exp:exps) = @@ -1031,7 +1030,7 @@ funTState [] = LocationTypeState $ M.empty -- | Look up the type of a variable from the environment -- Includes an expression for error reporting. -lookupVar :: Env2 Ty2 -> Var -> Exp -> TcM Ty2 +lookupVar :: Env2 Var Ty2 -> Var -> Exp -> TcM Ty2 lookupVar env var exp = case M.lookup var $ vEnv env of Nothing -> throwError $ VarNotFoundTC var exp @@ -1228,7 +1227,7 @@ removeLoc exp (LocationTypeState ls) l = then return $ LocationTypeState $ M.delete l ls else throwError $ GenericTC ("Cannot remove location " ++ (show l)) exp -ensureArenaScope :: MonadError TCError m => Exp -> Env2 a -> Maybe Var -> m () +ensureArenaScope :: MonadError TCError m => Exp -> Env2 Var a -> Maybe Var -> m () ensureArenaScope exp env ar = case ar of Nothing -> throwError $ GenericTC "Expected arena annotation" exp diff --git a/gibbon-compiler/src/Gibbon/L3/Syntax.hs b/gibbon-compiler/src/Gibbon/L3/Syntax.hs index 1274c289c..8519157c0 100644 --- a/gibbon-compiler/src/Gibbon/L3/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/L3/Syntax.hs @@ -289,7 +289,7 @@ cursorizeTy ty = -- | Map exprs with an initial type environment: -- Exactly the same function that was in L2 before -mapMExprs :: Monad m => (Env2 Ty3 -> Exp3 -> m Exp3) -> Prog3 -> m Prog3 +mapMExprs :: Monad m => (Env2 Var Ty3 -> Exp3 -> m Exp3) -> Prog3 -> m Prog3 mapMExprs fn (Prog ddfs fundefs mainExp) = Prog ddfs <$> (mapM (\f@FunDef{funArgs,funTy,funBody} -> diff --git a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs index 8c2372b8d..57beabf97 100644 --- a/gibbon-compiler/src/Gibbon/L3/Typecheck.hs +++ b/gibbon-compiler/src/Gibbon/L3/Typecheck.hs @@ -20,7 +20,7 @@ import Gibbon.L3.Syntax -- | Typecheck a L1 expression -- -tcExp :: Bool -> DDefs3 -> Env2 Ty3 -> Exp3 -> TcM Ty3 Exp3 +tcExp :: Bool -> DDefs3 -> Env2 Var Ty3 -> Exp3 -> TcM Ty3 Exp3 tcExp isPacked ddfs env exp = case exp of Ext ext -> @@ -903,7 +903,7 @@ tcProg isPacked prg@Prog{ddefs,fundefs,mainExp} = do return () -tcCases :: Bool -> DDefs3 -> Env2 Ty3 -> [(DataCon, [(Var, ())], Exp3)] -> TcM Ty3 (Exp3) +tcCases :: Bool -> DDefs3 -> Env2 Var Ty3 -> [(DataCon, [(Var, ())], Exp3)] -> TcM Ty3 (Exp3) tcCases isPacked ddfs env cs = do tys <- forM cs $ \(c,args',rhs) -> do let args = L.map fst args' diff --git a/gibbon-compiler/src/Gibbon/Language.hs b/gibbon-compiler/src/Gibbon/Language.hs index b6757df1c..f782b36a5 100644 --- a/gibbon-compiler/src/Gibbon/Language.hs +++ b/gibbon-compiler/src/Gibbon/Language.hs @@ -204,7 +204,7 @@ mapLocs :: (e l2 d -> e l2 d) -> PreExp e l2 d -> PreExp e l2 d mapLocs fn = visitExp id fn id -- | Transform the expressions within a program. -mapExprs :: (e -> e) -> Prog e -> Prog e +mapExprs :: (e -> e) -> Prog loc e -> Prog loc e mapExprs fn prg@Prog{fundefs,mainExp} = let mainExp' = case mainExp of Nothing -> Nothing @@ -214,7 +214,7 @@ mapExprs fn prg@Prog{fundefs,mainExp} = , mainExp = mainExp' } -- | Monadic 'mapExprs'. -mapMExprs :: Monad m => (e -> m e) -> Prog e -> m (Prog e) +mapMExprs :: Monad m => (e -> m e) -> Prog loc e -> m (Prog loc e) mapMExprs fn prg@Prog{fundefs,mainExp} = do mainExp' <- case mainExp of Nothing -> pure Nothing @@ -348,7 +348,7 @@ hasTimeIt rhs = Ext _ -> False WithArenaE _ e -> hasTimeIt e -hasSpawnsProg :: Prog (PreExp e l d) -> Bool +hasSpawnsProg :: Prog loc (PreExp e l d) -> Bool hasSpawnsProg (Prog _ fundefs mainExp) = any (\FunDef{funBody} -> hasSpawns funBody) (M.elems fundefs) || case mainExp of diff --git a/gibbon-compiler/src/Gibbon/Language/Syntax.hs b/gibbon-compiler/src/Gibbon/Language/Syntax.hs index 040055886..f4ee23ba9 100644 --- a/gibbon-compiler/src/Gibbon/Language/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/Language/Syntax.hs @@ -67,6 +67,7 @@ import Data.Functor.Foldable.TH import qualified Data.ByteString.Lazy.Char8 as B import Data.ByteString.Builder (Builder) import System.IO.Unsafe (unsafePerformIO) +--import qualified Data.Typeable as Typeable import Gibbon.Common @@ -179,7 +180,7 @@ class (Out (ArrowTy ty), Show (ArrowTy ty)) => FunctionTy ty where outTy :: ArrowTy ty -> ty -- | A set of top-level recursive function definitions. -type FunDefs ex = M.Map Var (FunDef ex) +type FunDefs loc ex = M.Map loc (FunDef loc ex) data FunRec = Rec | NotRec | TailRec deriving (Read, Show, Eq, Ord, Generic, NFData, Out) @@ -196,36 +197,44 @@ data FunMeta = FunMeta deriving (Read, Show, Eq, Ord, Generic, NFData, Out) -- | A function definiton indexed by a type and expression. -data FunDef ex = FunDef { funName :: Var - , funArgs :: [Var] - , funTy :: ArrowTy (TyOf ex) - , funBody :: ex - , funMeta :: FunMeta - } - -deriving instance (Read ex, Read (ArrowTy (TyOf ex))) => Read (FunDef ex) -deriving instance (Show ex, Show (ArrowTy (TyOf ex))) => Show (FunDef ex) -deriving instance (Eq ex, Eq (ArrowTy (TyOf ex))) => Eq (FunDef ex) -deriving instance (Ord ex, Ord (ArrowTy (TyOf ex))) => Ord (FunDef ex) -deriving instance Generic (FunDef ex) -deriving instance (Generic (ArrowTy (TyOf ex)), NFData ex, NFData (ArrowTy (TyOf ex))) => NFData (FunDef ex) -deriving instance (Generic (ArrowTy (TyOf ex)), Out ex, Out (ArrowTy (TyOf ex))) => Out (FunDef ex) +data FunDef loc ex = FunDef { funName :: Var + , funArgs :: [loc] + , funTy :: ArrowTy (TyOf ex) + , funBody :: ex + , funMeta :: FunMeta + } + +deriving instance (Read ex, Read (ArrowTy (TyOf ex)), Read loc) => Read (FunDef loc ex) +deriving instance (Show ex, Show (ArrowTy (TyOf ex)), Show loc) => Show (FunDef loc ex) +deriving instance (Eq ex, Eq (ArrowTy (TyOf ex)), Eq loc) => Eq (FunDef loc ex) +deriving instance (Ord ex, Ord (ArrowTy (TyOf ex)), Ord loc) => Ord (FunDef loc ex) +deriving instance Generic (FunDef loc ex) +deriving instance (Generic (ArrowTy (TyOf ex)), NFData ex, NFData (ArrowTy (TyOf ex)), NFData loc) => NFData (FunDef loc ex) +deriving instance (Generic (ArrowTy (TyOf ex)), Out ex, Out (ArrowTy (TyOf ex)), Out loc) => Out (FunDef loc ex) -- | Insert a 'FunDef' into 'FunDefs'. -- Raise an error if a function with the same name already exists. -insertFD :: FunDef ex -> FunDefs ex -> FunDefs ex +insertFD :: FunDef Var ex -> FunDefs Var ex -> FunDefs Var ex insertFD d = M.insertWith err' (funName d) d where err' = error $ "insertFD: function definition with duplicate name: "++show (funName d) +insertFD' :: FunDef LocVar ex -> FunDefs LocVar ex -> FunDefs LocVar ex +insertFD' d = M.insertWith err' (Single $ funName d) d + where + err' = error $ "insertFD: function definition with duplicate name: "++show (funName d) + -- | -fromListFD :: [FunDef ex] -> FunDefs ex +fromListFD :: [FunDef Var ex] -> FunDefs Var ex fromListFD = L.foldr insertFD M.empty -- | -initFunEnv :: FunDefs a -> TyEnv (ArrowTy (TyOf a)) +initFunEnv :: FunDefs Var a -> TyEnv Var (ArrowTy (TyOf a)) initFunEnv fds = M.map funTy fds +initFunEnv' :: FunDefs LocVar a -> TyEnv LocVar (ArrowTy (TyOf a)) +initFunEnv' fds = M.map funTy fds + -------------------------------------------------------------------------------- -- Programs -------------------------------------------------------------------------------- @@ -236,8 +245,8 @@ initFunEnv fds = M.map funTy fds -- datatype. For running a pass benchmark, main will be Nothing and -- we will expect a "benchmark" function definition which consumes an -- appropriate packed AST datatype. -data Prog ex = Prog { ddefs :: DDefs (TyOf ex) - , fundefs :: FunDefs ex +data Prog loc ex = Prog { ddefs :: DDefs (TyOf ex) + , fundefs :: FunDefs loc ex , mainExp :: Maybe (ex, (TyOf ex)) } @@ -245,78 +254,80 @@ data Prog ex = Prog { ddefs :: DDefs (TyOf ex) -- Ryan Scott recommended using singletons-like alternative outlined here: -- https://lpaste.net/365181 -- -deriving instance (Read (TyOf ex), Read ex, Read (ArrowTy (TyOf ex))) => Read (Prog ex) -deriving instance (Show (TyOf ex), Show ex, Show (ArrowTy (TyOf ex))) => Show (Prog ex) -deriving instance (Eq (TyOf ex), Eq ex, Eq (ArrowTy (TyOf ex))) => Eq (Prog ex) -deriving instance (Ord (TyOf ex), Ord ex, Ord (ArrowTy (TyOf ex))) => Ord (Prog ex) -deriving instance Generic (Prog ex) -deriving instance (NFData (TyOf ex), NFData (ArrowTy (TyOf ex)), NFData ex, Generic (ArrowTy (TyOf ex))) => NFData (Prog ex) +deriving instance (Read (TyOf ex), Read ex, Read (ArrowTy (TyOf ex)), Read loc, Ord loc) => Read (Prog loc ex) +deriving instance (Show (TyOf ex), Show ex, Show (ArrowTy (TyOf ex)), Show loc) => Show (Prog loc ex) +deriving instance (Eq (TyOf ex), Eq ex, Eq (ArrowTy (TyOf ex)), Eq loc) => Eq (Prog loc ex) +deriving instance (Ord (TyOf ex), Ord ex, Ord (ArrowTy (TyOf ex)), Eq loc, Ord loc) => Ord (Prog loc ex) +deriving instance Generic (Prog loc ex) +deriving instance (NFData (TyOf ex), NFData (ArrowTy (TyOf ex)), NFData ex, Generic (ArrowTy (TyOf ex)), NFData loc) => NFData (Prog loc ex) -- | Abstract some of the differences of top level program types, by -- having a common way to extract an initial environment. The -- initial environment has types only for functions. -progToEnv :: Prog a -> Env2 (TyOf a) +progToEnv :: Prog Var a -> Env2 Var (TyOf a) progToEnv Prog{fundefs} = Env2 M.empty (initFunEnv fundefs) +progToEnv' :: Prog LocVar a -> Env2 LocVar (TyOf a) +progToEnv' Prog{fundefs} = Env2 M.empty (initFunEnv' fundefs) + -- | Look up the input/output type of a top-level function binding. -getFunTy :: Var -> Prog ex -> ArrowTy (TyOf ex) +getFunTy :: Var -> Prog Var ex -> ArrowTy (TyOf ex) getFunTy fn Prog{fundefs} = case M.lookup fn fundefs of Just f -> funTy f Nothing -> error $ "getFunTy: L1 program does not contain binding for function: "++show fn instance (Generic (ArrowTy (TyOf ex)), Out (ArrowTy (TyOf ex)), - Out (TyOf ex), Out ex) => Out (Prog ex) + Out (TyOf ex), Out ex, Out loc) => Out (Prog loc ex) -------------------------------------------------------------------------------- -- Environments -------------------------------------------------------------------------------- -- | A simple type environment -type TyEnv a = M.Map Var a +type TyEnv a b = M.Map a b -emptyTyEnv :: TyEnv a +emptyTyEnv :: TyEnv a b emptyTyEnv = M.empty -- | A common currency for a two part environment consisting of -- function bindings and regular value bindings. -data Env2 a = Env2 { vEnv :: TyEnv a - , fEnv :: TyEnv (ArrowTy a) } - +data Env2 a b = Env2 { vEnv :: TyEnv a b + , fEnv :: TyEnv a (ArrowTy b) } -deriving instance (Show (TyOf a), Show a, Show (ArrowTy a)) => Show (Env2 a) -deriving instance (Read (TyOf a), Read a, Read (ArrowTy a)) => Read (Env2 a) -deriving instance (Eq (TyOf a), Eq a, Eq (ArrowTy a)) => Eq (Env2 a) --- deriving instance (Ord (TyOf a), Ord a, Ord (ArrowTy a)) => Ord (Env2 a) -deriving instance Generic (Env2 a) -instance (Out a, Out (ArrowTy a)) => Out (Env2 a) +deriving instance (Show (TyOf b), Show b, Show (ArrowTy b), Show a) => Show (Env2 a b) +deriving instance (Read (TyOf b), Read b, Read (ArrowTy b), Show a, Ord a, Read a) => Read (Env2 a b) +deriving instance (Eq (TyOf b), Eq b, Eq (ArrowTy b), Show a, Eq a) => Eq (Env2 a b) +deriving instance (Ord (TyOf b), Ord b, Ord (ArrowTy b), Ord a, Show a) => Ord (Env2 a b) +deriving instance Generic (Env2 a b) +instance (Out a, Out b, Out (ArrowTy b)) => Out (Env2 a b) -emptyEnv2 :: Env2 a +emptyEnv2 :: Env2 a b emptyEnv2 = Env2 { vEnv = emptyTyEnv , fEnv = M.empty } -- | Extend non-function value environment. -extendVEnv :: Var -> a -> Env2 a -> Env2 a +extendVEnv :: Var -> a -> Env2 Var a -> Env2 Var a extendVEnv v t (Env2 ve fe) = Env2 (M.insert v t ve) fe -- | Extend multiple times in one go. -extendsVEnv :: M.Map Var a -> Env2 a -> Env2 a +extendsVEnv :: M.Map Var a -> Env2 Var a -> Env2 Var a extendsVEnv mp (Env2 ve fe) = Env2 (M.union mp ve) fe -lookupVEnv :: Out a => Var -> Env2 a -> a +lookupVEnv :: Out a => Var -> Env2 Var a -> a lookupVEnv v env2 = (vEnv env2) # v -mblookupVEnv :: Var -> Env2 a -> Maybe a +mblookupVEnv :: Var -> Env2 Var a -> Maybe a mblookupVEnv cur env2 = M.lookup cur (vEnv env2) -lookupVEnv' :: Var -> Env2 a -> Maybe a +lookupVEnv' :: Var -> Env2 Var a -> Maybe a lookupVEnv' v (Env2 ve _) = M.lookup v ve -- | Extend function type environment. -extendFEnv :: Var -> ArrowTy a -> Env2 a -> Env2 a +extendFEnv :: Var -> ArrowTy a -> Env2 Var a -> Env2 Var a extendFEnv v t (Env2 ve fe) = Env2 ve (M.insert v t fe) -lookupFEnv :: Out (ArrowTy a) => Var -> Env2 a -> ArrowTy a +lookupFEnv :: Out (ArrowTy a) => Var -> Env2 Var a -> ArrowTy a lookupFEnv v env2 = (fEnv env2) # v @@ -597,12 +608,12 @@ class (Show e, Out e, FreeVars e) => Expression e where class Expression e => Flattenable e where -- | Process an expression into a fully-flattened expression which typically includes a -- larger number of temporary, local variable bindings. - gFlattenExp :: DDefs (TyOf e) -> Env2 (TyOf e) -> e -> PassM e + gFlattenExp :: DDefs (TyOf e) -> Env2 Var (TyOf e) -> e -> PassM e -- | A private method. Gather the bindings from a subexpression, -- but do not "discharge" them by creating a let expression. They -- are in order, so later may depend on earlier. - gFlattenGatherBinds :: DDefs (TyOf e) -> Env2 (TyOf e) -> e -> PassM ([Binds e],e) + gFlattenGatherBinds :: DDefs (TyOf e) -> Env2 Var (TyOf e) -> e -> PassM ([Binds e],e) type Binds e = (Var,[LocOf e],TyOf e, e) @@ -635,7 +646,7 @@ type HasSimplifiableExt e l d = ( Show l, Out l, Show d, Out d -- generic Flattenable, b/c we need to know the type of an expression before we -- bind it with a LetE. class Expression e => Typeable e where - gRecoverType :: DDefs (TyOf e) -> Env2 (TyOf e) -> e -> TyOf e + gRecoverType :: DDefs (TyOf e) -> Env2 Var (TyOf e) -> e -> TyOf e -- | Generic substitution over expressions. class Expression e => Substitutable e where @@ -689,23 +700,23 @@ runInterpM m s = do -- | Pure Gibbon programs, at any stage of compilation, should always -- be evaluatable to a unique value. The only side effects are timing. class Expression e => Interp s e where - gInterpExp :: RunConfig -> ValEnv e -> DDefs (TyOf e) -> FunDefs e -> e -> InterpM s e (Value e) + gInterpExp :: RunConfig -> ValEnv e -> DDefs (TyOf e) -> FunDefs loc e -> e -> InterpM s e (Value e) class (Expression e, Expression ext) => InterpExt s e ext where - gInterpExt :: RunConfig -> ValEnv e -> DDefs (TyOf e) -> FunDefs e -> ext -> InterpM s e (Value e) + gInterpExt :: RunConfig -> ValEnv e -> DDefs (TyOf e) -> FunDefs loc e -> ext -> InterpM s e (Value e) class Interp s e => InterpProg s e where {-# MINIMAL gInterpProg #-} - gInterpProg :: s -> RunConfig -> Prog e -> IO (s, Value e, B.ByteString) + gInterpProg :: s -> RunConfig -> Prog Var e -> IO (s, Value e, B.ByteString) -- | Interpret while ignoring timing constructs, and dropping the -- corresponding output to stdout. - gInterpNoLogs :: s -> RunConfig -> Prog e -> String + gInterpNoLogs :: s -> RunConfig -> Prog Var e -> String gInterpNoLogs s rc p = unsafePerformIO $ show . snd3 <$> gInterpProg s rc p -- | Interpret and produce a "log" of output lines, as well as a -- final, printed result. The output lines include timing information. - gInterpWithStdout :: s -> RunConfig -> Prog e -> IO (String,[String]) + gInterpWithStdout :: s -> RunConfig -> Prog Var e -> IO (String,[String]) gInterpWithStdout s rc p = do (_s1,res,logs) <- gInterpProg s rc p return (show res, lines (B.unpack logs)) @@ -758,7 +769,7 @@ instance Show e => Show (Value e) where VLam args bod env -> "(Clos (lambda (" ++ concat (map ((++" ") . show) args) ++ ") " ++ show bod ++ ") #{" ++ show env ++ "})" VWrapId vid val -> "(id: " ++ show vid ++ " " ++ show val ++ ")" -execAndPrint :: (InterpProg s ex) => s -> RunConfig -> Prog ex -> IO () +execAndPrint :: (InterpProg s ex) => s -> RunConfig -> Prog Var ex -> IO () execAndPrint s rc prg = do (_s1,val,logs) <- gInterpProg s rc prg B.putStr logs diff --git a/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs b/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs index 6d0730211..640554004 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/FromOldL2.hs @@ -36,7 +36,7 @@ fromOldL2Fn ddefs fundefs f@FunDef{funArgs,funTy,funBody} = do return $ f { funBody = bod', funTy = fmap New.MkTy2 funTy } -fromOldL2Exp :: DDefs Ty2 -> FunDefs2 -> LocEnv -> Env2 Ty2 -> Exp2 -> PassM New.Exp2 +fromOldL2Exp :: DDefs Ty2 -> FunDefs2 -> LocEnv -> Env2 Var Ty2 -> Exp2 -> PassM New.Exp2 fromOldL2Exp ddefs fundefs locenv env2 ex = case ex of AppE f locs args -> do @@ -84,7 +84,7 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = case lookupVEnv w env2 of PackedTy _ loc -> (loc:acc) -- For indirection/redirection pointers. - CursorTy -> (w:acc) + CursorTy -> ((Single w):acc) _ -> acc _ -> acc) [] @@ -93,8 +93,8 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = (ewitnesses', locenv'') = foldr (\(witloc, tloc) (wits, env) -> - let (New.Loc lrem) = (env # tloc) - wit' = New.EndWitness lrem witloc + let (New.Loc lrem) = (env # (tloc)) + wit' = New.EndWitness lrem (unwrapLocVar witloc) env' = M.insert witloc wit' env in (wit' : wits, env')) ([], locenv') @@ -134,7 +134,7 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = locenv locargs env2' = extendPatternMatchEnv dcon ddefs vars locs env2 locenv'' = if isRedirectionTag dcon || isIndirectionTag dcon - then let ptr = head vars + then let ptr = Single $ head vars in M.insert ptr (mkLocArg ptr) locenv' else locenv' rhs' <- go locenv'' env2' rhs @@ -173,7 +173,7 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = FromEndE loc -> Ext <$> FromEndE <$> pure (locenv # loc) BoundsCheck i reg loc -> do - let reg' = New.Reg reg Output + let reg' = New.Reg (unwrapLocVar reg) Output loc' = locenv # loc pure $ Ext $ BoundsCheck i reg' loc' @@ -189,8 +189,8 @@ fromOldL2Exp ddefs fundefs locenv env2 ex = IndirectionE tycon dcon - (locenv # from, New.EndOfReg from_reg Output (toEndV from_reg)) - (locenv # to, New.EndOfReg to_reg Input (toEndV to_reg)) + (locenv # from, New.EndOfReg (unwrapLocVar from_reg) Output (toEndV (unwrapLocVar from_reg))) + (locenv # to, New.EndOfReg (unwrapLocVar to_reg) Input (toEndV (unwrapLocVar to_reg))) e' -- (locenv # from, New.Reg (VarR from_reg) Output) -- (locenv # to, New.Reg (VarR to_reg) Input) diff --git a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs index 630dcd802..9cfbbde61 100644 --- a/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs +++ b/gibbon-compiler/src/Gibbon/NewL2/Syntax.hs @@ -107,6 +107,16 @@ toLocVar :: LocArg -> LocVar toLocVar arg = case arg of Loc lrm -> lremLoc lrm + EndWitness _ v -> Single v + Reg v _ -> Single v + EndOfReg _ _ v -> Single v + EndOfReg_Tagged v -> Single (toEndFromTaggedV v) + +-- Returns the data constructor +fromLocArgToVar :: LocArg -> Var +fromLocArgToVar arg = + case arg of + Loc lrm -> unwrapLocVar $ lremLoc lrm EndWitness _ v -> v Reg v _ -> v EndOfReg _ _ v -> v @@ -125,8 +135,8 @@ toEndFromTaggedV v = (toVar "end_from_tagged_") `varAppend` v instance FreeVars LocExp where gFreeVars e = case e of - Old.AfterConstantLE _ loc -> S.singleton (toLocVar loc) - Old.AfterVariableLE v loc _ -> S.fromList [v,toLocVar loc] + Old.AfterConstantLE _ loc -> S.singleton $ unwrapLocVar (toLocVar loc) + Old.AfterVariableLE v loc _ -> S.fromList $ [v, unwrapLocVar (toLocVar loc)] _ -> S.empty @@ -241,7 +251,7 @@ substLocs mp tys = L.map (substLoc mp) tys -- MkFoo (i:loc1) (f:loc2) -> -- new_env2 = extendPatternMatchEnv [loc1,loc2] old_env2 extendPatternMatchEnv :: HasCallStack => DataCon -> DDefs Ty2 -> [Var] -> [LocVar] - -> Env2 Ty2 -> Env2 Ty2 + -> Env2 Var Ty2 -> Env2 Var Ty2 extendPatternMatchEnv dcon ddefs vars locs env2 = let tys = lookupDataCon ddefs dcon tys' = foldr @@ -374,7 +384,7 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty let (vars,locs) = unzip vlocs acc'' = L.foldr (\w acc''' -> M.insertWith (++) v [w] acc''') acc' - (vars ++ (map toLocVar locs)) + (vars ++ (map (unwrapLocVar . toLocVar) locs)) in go acc'' e) acc mp @@ -393,7 +403,7 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty Old.LetParRegionE r _ _ rhs -> go (M.insertWith (++) (Old.regionToVar r) (S.toList $ allFreeVars rhs) acc) rhs Old.LetLocE loc phs rhs -> - go (M.insertWith (++) loc (dep phs ++ (S.toList $ allFreeVars rhs)) acc) rhs + go (M.insertWith (++) (unwrapLocVar loc) (dep phs ++ (S.toList $ allFreeVars rhs)) acc) rhs Old.RetE{} -> acc Old.FromEndE{} -> acc Old.BoundsCheck{} -> acc @@ -412,49 +422,49 @@ depList = L.map (\(a,b) -> (a,a,b)) . M.toList . go M.empty dep ex = case ex of Old.StartOfRegionLE r -> [Old.regionToVar r] - Old.AfterConstantLE _ loc -> [toLocVar loc] - Old.AfterVariableLE v loc _ -> [v,toLocVar loc] + Old.AfterConstantLE _ loc -> [unwrapLocVar $ toLocVar loc] + Old.AfterVariableLE v loc _ -> [v, unwrapLocVar $ toLocVar loc] Old.InRegionLE r -> [Old.regionToVar r] - Old.FromEndLE loc -> [toLocVar loc] + Old.FromEndLE loc -> [unwrapLocVar $ toLocVar loc] Old.FreeLE -> [] -- gFreeVars ++ locations ++ region variables allFreeVars :: Exp2 -> S.Set Var allFreeVars ex = case ex of - AppE _ locs args -> S.fromList (map toLocVar locs) `S.union` (S.unions (map allFreeVars args)) + AppE _ locs args -> S.fromList (map (unwrapLocVar . toLocVar) locs) `S.union` (S.unions (map allFreeVars args)) PrimAppE _ args -> (S.unions (map allFreeVars args)) - LetE (v,locs,_,rhs) bod -> (S.fromList (map toLocVar locs) `S.union` (allFreeVars rhs) `S.union` (allFreeVars bod)) + LetE (v,locs,_,rhs) bod -> (S.fromList (map (unwrapLocVar . toLocVar) locs) `S.union` (allFreeVars rhs) `S.union` (allFreeVars bod)) `S.difference` S.singleton v IfE a b c -> allFreeVars a `S.union` allFreeVars b `S.union` allFreeVars c MkProdE args -> (S.unions (map allFreeVars args)) ProjE _ bod -> allFreeVars bod CaseE scrt brs -> (allFreeVars scrt) `S.union` (S.unions (map (\(_,vlocs,c) -> allFreeVars c `S.difference` S.fromList (map fst vlocs) `S.difference` - S.fromList (map (toLocVar . snd) vlocs)) + S.fromList (map (unwrapLocVar . toLocVar . snd) vlocs)) brs)) - DataConE loc _ args -> S.singleton (toLocVar loc) `S.union` (S.unions (map allFreeVars args)) + DataConE loc _ args -> S.singleton ((unwrapLocVar . toLocVar) loc) `S.union` (S.unions (map allFreeVars args)) TimeIt e _ _ -> allFreeVars e WithArenaE _ e -> allFreeVars e - SpawnE _ locs args -> S.fromList (map toLocVar locs) `S.union` (S.unions (map allFreeVars args)) + SpawnE _ locs args -> S.fromList (map (unwrapLocVar . toLocVar) locs) `S.union` (S.unions (map allFreeVars args)) Ext ext -> case ext of Old.LetRegionE r _ _ bod -> S.delete (Old.regionToVar r) (allFreeVars bod) Old.LetParRegionE r _ _ bod -> S.delete (Old.regionToVar r) (allFreeVars bod) - Old.LetLocE loc locexp bod -> S.delete loc (allFreeVars bod `S.union` gFreeVars locexp) + Old.LetLocE loc locexp bod -> S.difference ((S.singleton . unwrapLocVar) loc) (allFreeVars bod `S.union` gFreeVars locexp) Old.StartOfPkdCursor v -> S.singleton v Old.TagCursor a b-> S.fromList [a,b] - Old.RetE locs v -> S.insert v (S.fromList (map toLocVar locs)) - Old.FromEndE loc -> S.singleton (toLocVar loc) - Old.BoundsCheck _ reg cur -> S.fromList (map toLocVar [reg, cur]) - Old.IndirectionE _ _ (a,b) (c,d) _ -> S.fromList $ [toLocVar a, toLocVar b, toLocVar c, toLocVar d] + Old.RetE locs v -> S.insert v (S.fromList (map (unwrapLocVar . toLocVar) locs)) + Old.FromEndE loc -> S.singleton ((unwrapLocVar . toLocVar) loc) + Old.BoundsCheck _ reg cur -> S.fromList (map (unwrapLocVar . toLocVar) [reg, cur]) + Old.IndirectionE _ _ (a,b) (c,d) _ -> S.fromList (map (unwrapLocVar . toLocVar) [a, b, c, d]) Old.AddFixed v _ -> S.singleton v Old.GetCilkWorkerNum-> S.empty Old.LetAvail vs bod -> S.fromList vs `S.union` gFreeVars bod - Old.AllocateTagHere loc _ -> S.singleton loc - Old.AllocateScalarsHere loc -> S.singleton loc - Old.SSPush _ a b _ -> S.fromList [a,b] - Old.SSPop _ a b -> S.fromList [a,b] + Old.AllocateTagHere loc _ -> S.singleton $ unwrapLocVar loc + Old.AllocateScalarsHere loc -> S.singleton $ unwrapLocVar loc + Old.SSPush _ a b _ -> S.fromList (map unwrapLocVar [a,b]) + Old.SSPop _ a b -> S.fromList (map unwrapLocVar [a,b]) _ -> gFreeVars ex freeLocVars :: Exp2 -> [Var] diff --git a/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs b/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs index 32aa6693b..7f659cebc 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddRAN.hs @@ -343,7 +343,7 @@ needsRAN Prog{ddefs,fundefs,mainExp} = type RegEnv = M.Map LocVar Var type TyConEnv = M.Map LocVar TyCon -needsRANExp :: DDefs Ty2 -> FunDefs2 -> Env2 Ty2 -> RegEnv -> TyConEnv -> [[LocVar]] -> Exp2 -> S.Set TyCon +needsRANExp :: DDefs Ty2 -> FunDefs2 -> Env2 Var Ty2 -> RegEnv -> TyConEnv -> [[LocVar]] -> Exp2 -> S.Set TyCon needsRANExp ddefs fundefs env2 renv tcenv parlocss ex = case ex of CaseE (VarE scrt) brs -> let PackedTy tycon tyloc = lookupVEnv scrt env2 @@ -444,7 +444,7 @@ we need random access for that type. in ran_for_scrt `S.union` needsRANExp ddefs fundefs env21' renv' tcenv1 parlocss1 bod -- Return the location and tycon of an argument to a function call. - parAppLoc :: Env2 Ty2 -> Exp2 -> M.Map LocVar TyCon + parAppLoc :: Env2 Var Ty2 -> Exp2 -> M.Map LocVar TyCon parAppLoc env21 (SpawnE _ _ args) = let fn (PackedTy dcon loc) = [(loc, dcon)] fn (ProdTy tys1) = L.concatMap fn tys1 diff --git a/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs b/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs index 87ce4f090..c9d79e9e8 100644 --- a/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs +++ b/gibbon-compiler/src/Gibbon/Passes/AddTraversals.hs @@ -54,7 +54,7 @@ addTraversalsFn ddefs fundefs f@FunDef{funName, funArgs, funTy, funBody} = do return $ f {funBody = bod'} -- Generate traversals for the first (n-1) packed elements -addTraversalsExp :: DDefs Ty2 -> FunDefs2 -> Env2 Ty2 -> RegEnv -> String -> Exp2 -> PassM Exp2 +addTraversalsExp :: DDefs Ty2 -> FunDefs2 -> Env2 Var Ty2 -> RegEnv -> String -> Exp2 -> PassM Exp2 addTraversalsExp ddefs fundefs env2 renv context ex = case ex of CaseE scrt@(VarE sv) brs -> do @@ -133,7 +133,7 @@ addTraversalsExp ddefs fundefs env2 renv context ex = -- If we cannot unpack all the pattern matched variables: -- (1) Everything after the first packed element should be unused in the RHS -- (2) Otherwise, we must traverse the first (n-1) packed elements -needsTraversalCase :: DDefs Ty2 -> FunDefs2 -> Env2 Ty2 -> (DataCon, [(Var, LocVar)], Exp2) -> Maybe [(Var, LocVar)] +needsTraversalCase :: DDefs Ty2 -> FunDefs2 -> Env2 Var Ty2 -> (DataCon, [(Var, LocVar)], Exp2) -> Maybe [(Var, LocVar)] needsTraversalCase ddefs fundefs env2 (dcon,vlocs,rhs) = if isAbsRANDataCon dcon || isRelRANDataCon dcon then Nothing else let (vars, _locs) = unzip vlocs diff --git a/gibbon-compiler/src/Gibbon/Passes/CalculateBounds.hs b/gibbon-compiler/src/Gibbon/Passes/CalculateBounds.hs index 32ba0a347..359190632 100644 --- a/gibbon-compiler/src/Gibbon/Passes/CalculateBounds.hs +++ b/gibbon-compiler/src/Gibbon/Passes/CalculateBounds.hs @@ -3,7 +3,7 @@ module Gibbon.Passes.CalculateBounds ( inferRegSize ) where import Gibbon.Common import qualified Data.Map as M -import Gibbon.L2.Syntax +import Gibbon.L2.Syntax as Old import qualified Data.List as L import Debug.Trace import Control.Monad @@ -15,10 +15,10 @@ type VarLocMapping = M.Map Var LocVar type RegionSizeMapping = M.Map Var RegionSize type RegionTypeMapping = M.Map Var RegionType -inferRegSize :: Prog2 -> PassM Prog2 +inferRegSize :: Old.Prog2 -> PassM Old.Prog2 inferRegSize = calculateBounds -calculateBounds :: Prog2 -> PassM Prog2 +calculateBounds :: Old.Prog2 -> PassM Old.Prog2 calculateBounds Prog { ddefs, fundefs, mainExp } = do let env2 = Env2 M.empty (initFunEnv fundefs) fundefs' <- mapM (calculateBoundsFun ddefs env2 M.empty) fundefs @@ -28,7 +28,7 @@ calculateBounds Prog { ddefs, fundefs, mainExp } = do return $ Prog ddefs fundefs' mainExp' -calculateBoundsFun :: DDefs Ty2 -> Env2 Ty2 -> VarSizeMapping -> FunDef2 -> PassM FunDef2 +calculateBoundsFun :: DDefs Old.Ty2 -> Env2 Var Old.Ty2 -> VarSizeMapping -> Old.FunDef2 -> PassM Old.FunDef2 calculateBoundsFun ddefs env2 varSzEnv f@FunDef { funName, funBody, funTy, funArgs } = do if "_" `L.isPrefixOf` fromVar funName then return f @@ -59,16 +59,16 @@ calculateBoundsFun ddefs env2 varSzEnv f@FunDef { funName, funBody, funTy, funAr * we will not update the region size inside that function . -} calculateBoundsExp - :: DDefs Ty2 -- ^ Data Definitions - -> Env2 Ty2 -- ^ Type Environment (Variables + Functions) + :: DDefs Old.Ty2 -- ^ Data Definitions + -> Env2 Var Old.Ty2 -- ^ Type Environment (Variables + Functions) -> VarSizeMapping -- ^ var => size -> VarLocMapping -- ^ var => location -> LocationRegionMapping -- ^ location => region -> LocationOffsetMapping -- ^ location => offset -> RegionSizeMapping -- ^ region => size -> RegionTypeMapping -- ^ region => type - -> Exp2 -- ^ expression - -> PassM (Exp2, RegionSizeMapping, RegionTypeMapping) + -> Old.Exp2 -- ^ expression + -> PassM (Old.Exp2, RegionSizeMapping, RegionTypeMapping) calculateBoundsExp ddefs env2 varSzEnv varLocEnv locRegEnv locOffEnv regSzEnv regTyEnv ex = case ex of Ext (BoundsCheck{}) -> return (ex, regSzEnv, regTyEnv) Ext (IndirectionE _tycon _dcon (fromLoc, _fromvar) (toLoc, _tovar) _exp) -> do @@ -134,7 +134,7 @@ calculateBoundsExp ddefs env2 varSzEnv varLocEnv locRegEnv locOffEnv regSzEnv re (cases', res, rts) <- unzip3 <$> mapM - (\(dcon :: DataCon, vlocs :: [(Var, LocVar)], bod :: Exp2) -> do + (\(dcon :: DataCon, vlocs :: [(Var, LocVar)], bod :: Old.Exp2) -> do -- TODO use for traversal somewhere down the line? -- let offsets = -- M.fromList @@ -170,7 +170,7 @@ calculateBoundsExp ddefs env2 varSzEnv varLocEnv locRegEnv locOffEnv regSzEnv re return (Ext $ LetParRegionE reg regSz regTy bod', re, rt) LetLocE loc locExp ex1 -> do -- * NOTE: jumps are only necessary for route ends, skipping them. - if "jump_" `L.isPrefixOf` fromVar loc + if "jump_" `L.isPrefixOf` fromVar (unwrapLocVar loc) then do (ex1', re', rt') <- go ex1 return (Ext $ LetLocE loc locExp ex1', re', rt') diff --git a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs index 32483f4ab..887cb81b1 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Cursorize.hs @@ -116,7 +116,7 @@ cursorizeFunDef ddefs fundefs FunDef{funName,funTy,funArgs,funBody,funMeta} = do -- intuitive and can be improved. -- Input & output regions are always inserted before all other arguments. - regBinds = map toEndV (inRegs ++ outRegs) + regBinds = map toEndVLoc (inRegs ++ outRegs) -- Output cursors after that. outCurBinds = outLocs @@ -126,13 +126,13 @@ cursorizeFunDef ddefs fundefs FunDef{funName,funTy,funArgs,funBody,funMeta} = do [] -> mkLets [] _ -> let projs = concatMap (\(e,t) -> mkInProjs e t) (zip (map VarE funArgs) in_tys) - bnds = [(loc,[],CursorTy,proj) | (loc,proj) <- zip inLocs projs] + bnds = [((unwrapLocVar loc),[],CursorTy,proj) | (loc,proj) <- zip inLocs projs] in mkLets bnds - initTyEnv = M.fromList $ (map (\(a,b) -> (a,MkTy2 (cursorizeInTy (unTy2 b)))) $ zip funArgs in_tys) ++ + initTyEnv = M.fromList $ (map (\(a,b) -> (Single a,MkTy2 (cursorizeInTy (unTy2 b)))) $ zip funArgs in_tys) ++ [(a, MkTy2 CursorTy) | (LRM a _ _) <- locVars funTy] - funargs = regBinds ++ outCurBinds ++ funArgs + funargs = regBinds ++ outCurBinds ++ (map Single funArgs) bod <- if hasPacked (unTy2 out_ty) then fromDi <$> cursorizePackedExp ddefs fundefs M.empty initTyEnv M.empty funBody @@ -235,7 +235,7 @@ This is used to create bindings for input location variables. -- | Cursorize expressions NOT producing `Packed` values -cursorizeExp :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 +cursorizeExp :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv LocVar Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeExp ddfs fundefs denv tenv senv ex = case ex of @@ -398,7 +398,7 @@ cursorizeExp ddfs fundefs denv tenv senv ex = -- Cursorize expressions producing `Packed` values -cursorizePackedExp :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 +cursorizePackedExp :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv LocVar Ty2 -> SyncEnv -> Exp2 -> PassM (DiExp Exp3) cursorizePackedExp ddfs fundefs denv tenv senv ex = case ex of @@ -668,7 +668,7 @@ cursorizePackedExp ddfs fundefs denv tenv senv ex = dl = Di -cursorizeReadPackedFile :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Bool -> Var +cursorizeReadPackedFile :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Bool -> Var -> Maybe FilePath -> TyCon -> Maybe Var -> Ty2 -> Exp2 -> PassM Exp3 cursorizeReadPackedFile ddfs fundefs denv tenv senv isPackedContext v path tyc reg ty2 bod = do @@ -691,7 +691,7 @@ cursorizeReadPackedFile ddfs fundefs denv tenv senv isPackedContext v path tyc r -- -- i.e `loc_a` may not always be bound. If that's the case, don't process `loc_b` -- now. Instead, add it to the dependency environment. -cursorizeLocExp :: DepEnv -> TyEnv Ty2 -> SyncEnv -> LocVar -> LocExp -> Either DepEnv (Exp3, [Binds Exp3], TyEnv Ty2, SyncEnv) +cursorizeLocExp :: DepEnv -> TyEnv Var Ty2 -> SyncEnv -> LocVar -> LocExp -> Either DepEnv (Exp3, [Binds Exp3], TyEnv Var Ty2, SyncEnv) cursorizeLocExp denv tenv senv lvar locExp = case locExp of AfterConstantLE i loc -> @@ -788,7 +788,7 @@ But Infinite regions do not support sizes yet. Re-enable this later. -- safely drop them from `locs`. -- -- (2) We update `arg` so that all packed values in it only have start cursors. -cursorizeAppE :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeAppE :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeAppE ddfs fundefs denv tenv senv ex = case ex of AppE f locs args -> do @@ -845,7 +845,7 @@ There are two ways in which projections can be cursorized: `cursorizeLet` creates the former, while the special case here outputs the latter. Reason: unariser can only eliminate direct projections of this form. -} -cursorizeProj :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeProj :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeProj isPackedContext ddfs fundefs denv tenv senv ex = case ex of LetE (v,_locs,ty, rhs@ProjE{}) bod | isPackedTy (unTy2 ty) -> do @@ -883,7 +883,7 @@ If it's just `CursorTy`, this packed value doesn't have an end cursor, otherwise, the type is `PackedTy{}`, and it also has an end cursor. -} -cursorizeProd :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeProd :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeProd isPackedContext ddfs fundefs denv tenv senv ex = case ex of LetE (v, _locs, MkTy2 (ProdTy tys), rhs@(MkProdE ls)) bod -> do @@ -917,7 +917,7 @@ and add fewer things to the type environemnt because we have to wait until the join point. -} -cursorizeSpawn :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeSpawn :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeSpawn isPackedContext ddfs fundefs denv tenv senv ex = do case ex of LetE (v, locs, MkTy2 ty, (SpawnE fn applocs args)) bod @@ -1011,7 +1011,7 @@ cursorizeSpawn isPackedContext ddfs fundefs denv tenv senv ex = do then fromDi <$> cursorizePackedExp ddfs fundefs denv t s x else cursorizeExp ddfs fundefs denv t s x -cursorizeSync :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 +cursorizeSync :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Exp2 -> PassM Exp3 cursorizeSync isPackedContext ddfs fundefs denv tenv senv ex = do case ex of LetE (v, _locs, MkTy2 ty, SyncE) bod -> do @@ -1050,7 +1050,7 @@ we can take a shortcut here and directly bind `v` to the tagged location. Other bindings are straightforward projections of the processed RHS. -} -cursorizeLet :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv +cursorizeLet :: Bool -> DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> (Var, [LocArg], Ty2, Exp2) -> Exp2 -> PassM Exp3 cursorizeLet isPackedContext ddfs fundefs denv tenv senv (v,locs,(MkTy2 ty),rhs) bod | isPackedTy ty = do @@ -1166,7 +1166,7 @@ Consider an example of unpacking of a Node^ pattern: ..TODO.. -} -unpackDataCon :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Ty2 -> SyncEnv -> Bool -> Var +unpackDataCon :: DDefs Ty2 -> FunDefs2 -> DepEnv -> TyEnv Var Ty2 -> SyncEnv -> Bool -> Var -> (DataCon, [(Var, LocArg)], Exp2) -> PassM (DataCon, [t], Exp3) unpackDataCon ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon,vlocs1,rhs) = do field_cur <- gensym "field_cur" @@ -1201,7 +1201,7 @@ unpackDataCon ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon,vlocs1,rhs) = unpackRegularDataCon :: Var -> PassM Exp3 unpackRegularDataCon field_cur = go field_cur vlocs1 tys1 True denv1 (M.insert field_cur (MkTy2 CursorTy) tenv1) where - go :: Var -> [(Var, LocArg)] -> [Ty2] -> Bool -> DepEnv -> TyEnv Ty2 -> PassM Exp3 + go :: Var -> [(Var, LocArg)] -> [Ty2] -> Bool -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 go cur vlocs tys canBind denv tenv = case (vlocs, tys) of ([],[]) -> processRhs denv tenv @@ -1343,7 +1343,7 @@ unpackDataCon ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon,vlocs1,rhs) = in M.fromList $ zip vars (zip var_locs ind_vars) in go field_cur vlocs1 tys1 ran_mp denv1 (M.insert field_cur (MkTy2 CursorTy) tenv1) where - go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var,Var) -> DepEnv -> TyEnv Ty2 -> PassM Exp3 + go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var,Var) -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 go cur vlocs tys indirections_env denv tenv = do case (vlocs, tys) of ([], []) -> processRhs denv tenv @@ -1486,7 +1486,7 @@ unpackDataCon ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon,vlocs1,rhs) = in M.fromList $ zip vars (zip var_locs (map (\(x,y) -> (x,toLocVar y)) inds)) in go field_cur vlocs1 tys1 ran_mp denv1 (M.insert field_cur (MkTy2 CursorTy) tenv1) where - go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var,(Var,Var)) -> DepEnv -> TyEnv Ty2 -> PassM Exp3 + go :: Var -> [(Var, LocArg)] -> [Ty2] -> M.Map Var (Var,(Var,Var)) -> DepEnv -> TyEnv Var Ty2 -> PassM Exp3 go cur vlocs tys indirections_env denv tenv = do case (vlocs, tys) of ([], []) -> processRhs denv tenv @@ -1530,7 +1530,7 @@ unpackDataCon ddfs fundefs denv1 tenv1 senv isPacked scrtCur (dcon,vlocs1,rhs) = _ -> error $ "unpackWithRelRAN: Unexpected numnber of varible, type pairs: " ++ show (vlocs,tys) -- Generate bindings for unpacking int fields. A convenient - scalarBinds :: OldTy2 -> Var -> LocVar -> TyEnv Ty2 -> PassM (TyEnv Ty2, [(Var, [()], Ty3, Exp3)]) + scalarBinds :: OldTy2 -> Var -> LocVar -> TyEnv Var Ty2 -> PassM (TyEnv Var Ty2, [(Var, [()], Ty3, Exp3)]) scalarBinds ty v loc tenv = do tmp <- gensym "read_scalar_tuple" -- Note that the location is not added to the type environment here. @@ -1593,7 +1593,7 @@ regionToBinds for_parallel_allocs r sz = Undefined -> mul -isBound :: LocVar -> TyEnv Ty2 -> Bool +isBound :: LocVar -> TyEnv Var Ty2 -> Bool isBound = M.member -- ================================================================================ diff --git a/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs b/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs index ec862b403..80e061078 100644 --- a/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs +++ b/gibbon-compiler/src/Gibbon/Passes/DirectL3.hs @@ -37,7 +37,7 @@ directL3 prg@(Prog ddfs fndefs mnExp) = do , funMeta = funMeta } - go :: Env2 Ty1 -> Exp1 -> Exp3 + go :: Env2 Var Ty1 -> Exp1 -> Exp3 go env2 ex = case ex of VarE v -> VarE v diff --git a/gibbon-compiler/src/Gibbon/Passes/FindWitnesses.hs b/gibbon-compiler/src/Gibbon/Passes/FindWitnesses.hs index eb0e58483..728087968 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FindWitnesses.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FindWitnesses.hs @@ -50,8 +50,10 @@ bigNumber = 10 -- limit number of loops findWitnesses :: Prog2 -> PassM Prog2 findWitnesses p@Prog{fundefs} = mapMExprs fn p where - fn Env2{vEnv,fEnv} boundlocs ex = return (goFix (Map.keysSet vEnv `Set.union` Map.keysSet fEnv - `Set.union` boundlocs + fn Env2{vEnv,fEnv} boundlocs ex = do + let boundlocs' = Set.fromList $ map unwrapLocVar $ Set.toList boundlocs + return (goFix (Map.keysSet vEnv `Set.union` Map.keysSet fEnv + `Set.union` boundlocs' ) ex bigNumber) goFix _ ex 0 = error $ "timeout in findWitness on " ++ (show ex) @@ -62,7 +64,7 @@ findWitnesses p@Prog{fundefs} = mapMExprs fn p docase bound mp (k,vs,e) = let (vars,locs) = unzip vs - bound' = Set.fromList (vars ++ locs) `Set.union` bound + bound' = Set.fromList (vars ++ (map unwrapLocVar locs)) `Set.union` bound in (k,vs,goE bound' mp e) goE :: Set.Set Var -> Map.Map Var DelayedBind -> Exp2 -> Exp2 @@ -84,14 +86,14 @@ findWitnesses p@Prog{fundefs} = mapMExprs fn p chk = Set.null freelocs in if chk -- dbgTraceIt (if loc == "loc_17052" then (sdoc (loc, locexp, freelocs, chk)) else "") - then Ext $ LetLocE loc locexp $ goE (Set.insert loc bound) mp bod + then Ext $ LetLocE loc locexp $ goE (Set.insert (unwrapLocVar loc) bound) mp bod else case locexp of AfterVariableLE v loc2 b -> - (go (Map.insert loc (DelayLoc (loc, (AfterVariableLE v loc2 b))) mp) bod) + (go (Map.insert (unwrapLocVar loc) (DelayLoc (loc, (AfterVariableLE v loc2 b))) mp) bod) AfterConstantLE i loc2 -> - go (Map.insert loc (DelayLoc (loc, (AfterConstantLE i loc2))) mp) bod - _ -> Ext $ LetLocE loc locexp $ goE (Set.insert loc bound) mp bod + go (Map.insert (unwrapLocVar loc) (DelayLoc (loc, (AfterConstantLE i loc2))) mp) bod + _ -> Ext $ LetLocE loc locexp $ goE (Set.insert (unwrapLocVar loc) bound) mp bod LetRegionE r sz ty bod -> Ext $ LetRegionE r sz ty $ go mp bod LetParRegionE r sz ty bod -> Ext $ LetParRegionE r sz ty $ go mp bod _ -> handle' $ ex @@ -196,13 +198,13 @@ closed bound mp = Set.null (allBound `Set.difference` allUsed) DelayLoc (_,locexp) -> gFreeVars locexp) (Map.elems mp) -mapMExprs :: Monad m => (Env2 Ty2 -> Set.Set LocVar -> Exp2 -> m Exp2) -> Prog2 -> m Prog2 +mapMExprs :: Monad m => (Env2 Var Ty2 -> Set.Set LocVar -> Exp2 -> m Exp2) -> Prog2 -> m Prog2 mapMExprs fn (Prog ddfs fundefs mainExp) = Prog ddfs <$> (mapM (\f@FunDef{funArgs,funTy,funBody} -> let env = Env2 (Map.fromList $ zip funArgs (inTys funTy)) funEnv boundlocs = Set.fromList (allLocVars funTy) `Set.union` - Set.fromList funArgs + Set.fromList (map Single funArgs) in do bod' <- fn env boundlocs funBody return $ f { funBody = bod' }) diff --git a/gibbon-compiler/src/Gibbon/Passes/Flatten.hs b/gibbon-compiler/src/Gibbon/Passes/Flatten.hs index ff5004451..985c285cb 100644 --- a/gibbon-compiler/src/Gibbon/Passes/Flatten.hs +++ b/gibbon-compiler/src/Gibbon/Passes/Flatten.hs @@ -107,7 +107,7 @@ instance FlattenDeps e l d => Flattenable (PreExp e l d) where exp :: forall e l d. FlattenDeps e l d => DDefs (TyOf (PreExp e l d)) - -> Env2 (TyOf (PreExp e l d)) + -> Env2 Var (TyOf (PreExp e l d)) -> (PreExp e l d) -> PassM ([Binds (PreExp e l d)], (PreExp e l d)) exp ddfs env2 e0 = @@ -210,7 +210,7 @@ flattenL0 prg@(Prog defs funs main) = do return $ FunDef nam nargs ty bod' meta env20 = progToEnv prg -flattenExp0 :: L0.DDefs0 -> Env2 L0.Ty0 -> L0.Exp0 +flattenExp0 :: L0.DDefs0 -> Env2 Var L0.Ty0 -> L0.Exp0 -> PassM ([Binds (L0.Exp0)], L0.Exp0) flattenExp0 ddfs env2 e0 = let triv :: String -> L0.Exp0 -> PassM ([Binds (L0.Exp0)], L0.Exp0) diff --git a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs index e0ffff9fa..1afc2e299 100644 --- a/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs +++ b/gibbon-compiler/src/Gibbon/Passes/FollowPtrs.hs @@ -28,7 +28,7 @@ followPtrs (Prog ddefs fundefs mainExp) = do funBody' <- go (M.fromList (zip funArgs in_tys)) out_ty funName funArgs funTy funBody pure $ f { funBody = funBody' } - go env out_ty funName funArgs funTy e = + go env out_ty funName funArgs funTy e = case e of CaseE scrt brs -> do let VarE scrtv = scrt @@ -41,31 +41,32 @@ followPtrs (Prog ddefs fundefs mainExp) = do callv <- gensym "call" let _effs = arrEffs funTy endofs <- mapM (\_ -> gensym "endof") (locRets funTy) + let endofs' = map Single endofs let ret_endofs = foldr (\(end, (EndOf (LRM loc _ _))) acc -> if loc == scrt_loc - then jump : acc + then (Single jump) : acc else end : acc) [] - (zip endofs (locRets funTy)) + (zip endofs' (locRets funTy)) let args = foldr (\v acc -> if v == scrtv then ((VarE indir_ptrv) : acc) else (VarE v : acc)) [] funArgs - let in_locs = foldr (\loc acc -> if loc == scrt_loc then (indir_ptrv : acc) else (loc : acc)) [] (inLocVars funTy) + let in_locs = foldr (\loc acc -> if loc == scrt_loc then ((Single indir_ptrv) : acc) else (loc : acc)) [] (inLocVars funTy) let out_locs = outLocVars funTy wc <- gensym "wildcard" - let indir_bod = Ext $ LetLocE jump (AfterConstantLE 8 indir_ptrloc) $ + let indir_bod = Ext $ LetLocE (Single jump) (AfterConstantLE 8 (Single indir_ptrloc)) $ (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->i ")]) else id) $ - LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ + LetE (callv,endofs',out_ty,AppE funName (in_locs ++ out_locs) args) $ Ext (RetE ret_endofs callv) let indir_dcon = fst $ fromJust $ L.find (isIndirectionTag . fst) dataCons - let indir_br = (indir_dcon,[(indir_ptrv,indir_ptrloc)],indir_bod) + let indir_br = (indir_dcon,[(indir_ptrv,(Single indir_ptrloc))],indir_bod) ---------------------------------------- let redir_dcon = fst $ fromJust $ L.find (isRedirectionTag . fst) dataCons let redir_bod = (if isPrinterName funName then LetE (wc,[],ProdTy[],PrimAppE PrintSym [LitSymE (toVar " ->r ")]) else id) $ - LetE (callv,endofs,out_ty,AppE funName (in_locs ++ out_locs) args) $ - Ext (RetE endofs callv) - let redir_br = (redir_dcon,[(indir_ptrv,indir_ptrloc)],redir_bod) + LetE (callv,endofs',out_ty,AppE funName (in_locs ++ out_locs) args) $ + Ext (RetE endofs' callv) + let redir_br = (redir_dcon,[(indir_ptrv,(Single indir_ptrloc))],redir_bod) ---------------------------------------- (pure (CaseE scrt (brs ++ [indir_br,redir_br]))) IfE a b c -> do diff --git a/gibbon-compiler/src/Gibbon/Passes/InferEffects.hs b/gibbon-compiler/src/Gibbon/Passes/InferEffects.hs index 0c663be7e..ca69947b2 100644 --- a/gibbon-compiler/src/Gibbon/Passes/InferEffects.hs +++ b/gibbon-compiler/src/Gibbon/Passes/InferEffects.hs @@ -73,7 +73,7 @@ inferFunDef ddfs fenv FunDef{funArgs,funBody,funTy} = funTy { arrEffs = S.inters (eff,_outLoc) = inferExp ddfs fenv env0 M.empty funBody -inferExp :: DDefs Ty2 -> FunEnv2 -> TyEnv Ty2 -> Deps -> Exp2 -> (Set Effect, Maybe LocVar) +inferExp :: DDefs Ty2 -> FunEnv2 -> TyEnv Var Ty2 -> Deps -> Exp2 -> (Set Effect, Maybe LocVar) inferExp ddfs fenv env dps expr = case expr of -- QUESTION: does a variable reference count as traversing to the end?