@@ -1112,92 +1112,6 @@ reOrderLetExpHelper Nothing letExpOrder expr = case letExpOrder of
11121112 in exp'
11131113 _ -> error " reOrderLetExpHelper: did not expect expressions other than LetE."
11141114
1115- -- reOrderLetExpHelper Nothing letExpOrder expr = let
1116-
1117- -- case expr of
1118- -- DataConE loc dcon args ->
1119- -- VarE {} ->
1120- -- LitE {} ->
1121- -- CharE {} ->
1122- -- FloatE {} ->
1123- -- LitSymE {} ->
1124- -- AppE f locs args ->
1125- -- PrimAppE f args ->
1126- -- LetE (v, loc, ty, rhs) bod ->
1127- -- CaseE scrt mp ->
1128- -- IfE a b c ->
1129- -- MkProdE xs ->
1130- -- ProjE {} -> error "reOrderLetExpHelper: TODO ProjE"
1131- -- TimeIt {} -> error "reOrderLetExpHelper: TODO TimeIt"
1132- -- WithArenaE {} -> error "reOrderLetExpHelper: TODO WithArenaE"
1133- -- SpawnE {} -> error "reOrderLetExpHelper: TODO SpawnE"
1134- -- SyncE -> error "reOrderLetExpHelper: TODO SyncE"
1135- -- Ext {} -> error "reOrderLetExpHelper: TODO Ext"
1136- -- MapE {} -> error "reOrderLetExpHelper: TODO MapE"
1137- -- FoldE {} -> error "reOrderLetExpHelper: TODO FoldE"
1138-
1139- -- reOrderLetExpHelper insertAfter@(Just var) letExpOrder expr = case expr of
1140- -- DataConE loc dcon args -> DataConE loc dcon $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1141- -- VarE {} -> expr
1142- -- LitE {} -> expr
1143- -- CharE {} -> expr
1144- -- FloatE {} -> expr
1145- -- LitSymE {} -> expr
1146- -- AppE f locs args -> AppE f locs $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1147- -- PrimAppE f args -> PrimAppE f $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1148- -- LetE (v, loc, ty, rhs) bod -> if v == var
1149- -- then
1150- -- let lambda = (\l ex -> case l of
1151- -- LetE (v', loc', ty', rhs') _ -> LetE (v', loc', ty', rhs') ex
1152- -- _ -> error "reOrderLetExpHelper: did not expect expressions other than LetE.")
1153- -- exp' = P.foldr lambda bod letExpOrder
1154- -- in LetE (v, loc, ty, rhs) exp'
1155- -- else
1156- -- LetE (v, loc, ty, reOrderLetExpHelper insertAfter letExpOrder rhs) (reOrderLetExpHelper insertAfter letExpOrder bod)
1157- -- CaseE scrt mp -> CaseE scrt $ P.map (\(a, b, c) -> (a, b, reOrderLetExpHelper insertAfter letExpOrder c)) mp
1158- -- IfE a b c -> IfE (reOrderLetExpHelper insertAfter letExpOrder a) (reOrderLetExpHelper insertAfter letExpOrder b) (reOrderLetExpHelper insertAfter letExpOrder c)
1159- -- MkProdE xs -> MkProdE $ P.map (reOrderLetExpHelper insertAfter letExpOrder) xs
1160- -- ProjE {} -> error "reOrderLetExpHelper: TODO ProjE"
1161- -- TimeIt {} -> error "reOrderLetExpHelper: TODO TimeIt"
1162- -- WithArenaE {} -> error "reOrderLetExpHelper: TODO WithArenaE"
1163- -- SpawnE {} -> error "reOrderLetExpHelper: TODO SpawnE"
1164- -- SyncE -> error "reOrderLetExpHelper: TODO SyncE"
1165- -- Ext {} -> error "reOrderLetExpHelper: TODO Ext"
1166- -- MapE {} -> error "reOrderLetExpHelper: TODO MapE"
1167- -- FoldE {} -> error "reOrderLetExpHelper: TODO FoldE"
1168-
1169- -- TODO: This will release bindings multiple times for variables use everywhere, whreas we want to just prioritize for first use.
1170- -- Simple solution is to refactor this into a new function and return a bool when the binds have been released.
1171- -- check if binds have been released, if pass [] as let binds.
1172- -- reOrderLetExpHelper insertAfter@(Just var) letExpOrder expr = case expr of
1173- -- DataConE loc dcon args -> DataConE loc dcon $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1174- -- VarE vv -> if vv == var
1175- -- then
1176- -- let lambda = (\l ex -> case l of
1177- -- LetE (v', loc', ty', rhs') _ -> LetE (v', loc', ty', rhs') ex
1178- -- _ -> error "reOrderLetExpHelper: did not expect expressions other than LetE.")
1179- -- exp' = P.foldr lambda expr letExpOrder
1180- -- in exp'
1181- -- else
1182- -- expr
1183- -- LitE {} -> expr
1184- -- CharE {} -> expr
1185- -- FloatE {} -> expr
1186- -- LitSymE {} -> expr
1187- -- AppE f locs args -> AppE f locs $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1188- -- PrimAppE f args -> PrimAppE f $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1189- -- LetE (v, loc, ty, rhs) bod -> LetE (v, loc, ty, reOrderLetExpHelper insertAfter letExpOrder rhs) (reOrderLetExpHelper insertAfter letExpOrder bod)
1190- -- CaseE scrt mp -> CaseE scrt $ P.map (\(a, b, c) -> (a, b, reOrderLetExpHelper insertAfter letExpOrder c)) mp
1191- -- IfE a b c -> IfE (reOrderLetExpHelper insertAfter letExpOrder a) (reOrderLetExpHelper insertAfter letExpOrder b) (reOrderLetExpHelper insertAfter letExpOrder c)
1192- -- MkProdE xs -> MkProdE $ P.map (reOrderLetExpHelper insertAfter letExpOrder) xs
1193- -- ProjE {} -> error "reOrderLetExpHelper: TODO ProjE"
1194- -- TimeIt {} -> error "reOrderLetExpHelper: TODO TimeIt"
1195- -- WithArenaE {} -> error "reOrderLetExpHelper: TODO WithArenaE"
1196- -- SpawnE {} -> error "reOrderLetExpHelper: TODO SpawnE"
1197- -- SyncE -> error "reOrderLetExpHelper: TODO SyncE"
1198- -- Ext {} -> error "reOrderLetExpHelper: TODO Ext"
1199- -- MapE {} -> error "reOrderLetExpHelper: TODO MapE"
1200- -- FoldE {} -> error "reOrderLetExpHelper: TODO FoldE"
12011115
12021116reOrderLetExpHelper bindsForVar@ (Just var) letExpOrder expr = fst $ run letExpOrder expr
12031117 where
@@ -1298,59 +1212,6 @@ delLetBinding letBind expr = case expr of
12981212 FoldE {} -> error " delLetBinding: TODO FoldE"
12991213
13001214
1301-
1302-
1303-
1304-
1305-
1306-
1307-
1308-
1309-
1310-
1311-
1312-
1313-
1314-
1315- -- reorderExpByVariablesBoundByDataCon :: DataCon -> FunDef1 -> [[Exp1]]
1316- -- reorderExpByVariablesBoundByDataCon dcon fundef@FunDef{funName,funBody,funTy,funArgs} initialEnv = let
1317- -- dconVars = getVarsBoundByDconInOrder dcon funBody
1318- -- exps = P.map (\var -> getBoundExpsVar var funBody []) dconVars
1319- -- in exps
1320-
1321-
1322-
1323- -- getBoundExpsVar :: Var -> Exp1 -> S.Set Exp1 -> [Exp1]
1324- -- getBoundExpsVar var exp liveExpressions = case exp of
1325- -- DataConE loc dcon args -> P.concatMap (\ex -> getBoundExpsVar var ex liveExpressions) args
1326- -- VarE {} -> []
1327- -- LitE {} -> []
1328- -- CharE {} -> []
1329- -- FloatE {} -> []
1330- -- LitSymE {} -> []
1331- -- AppE f locs args -> P.concatMap (\ex -> getBoundExpsVar var ex liveExpressions) args
1332- -- PrimAppE f args -> P.concatMap (\ex -> getBoundExpsVar var ex liveExpressions) args
1333- -- LetE (v, loc, ty, rhs) bod -> if v == var
1334- -- then let freeExprs = gFreeVars rhs
1335- -- releaseBinds = P.map (\var -> P.map (\exp -> case exp of
1336- -- LetE (v', _, _, _) b -> if v' == var then [exp]
1337- -- else []
1338- -- ) S.toList liveExpressions
1339- -- ) S.toList freeExprs
1340-
1341- -- CaseE scrt mp ->
1342- -- IfE a b c ->
1343- -- MkProdE xs ->
1344- -- ProjE i e -> error "getExpTyEnv: TODO ProjE"
1345- -- TimeIt e ty b -> error "getExpTyEnv: TODO TimeIt"
1346- -- WithArenaE v e -> error "getExpTyEnv: TODO WithArenaE"
1347- -- SpawnE f locs args -> error "getExpTyEnv: TODO SpawnE"
1348- -- SyncE -> error "getExpTyEnv: TODO SyncE"
1349- -- Ext _ -> error "getExpTyEnv: TODO Ext"
1350- -- MapE {} -> error "getExpTyEnv: TODO MapE"
1351- -- FoldE {} -> error "getExpTyEnv: TODO FoldE"
1352-
1353-
13541215genPrintFnCase :: (DataCon , [(IsBoxed , Ty1 )]) -> PassM (DataCon , [(Var , () )], PreExp E1Ext () Ty1 )
13551216genPrintFnCase (dcon, tys) = do
13561217 xs <- mapM (\ _ -> gensym " x" ) tys
@@ -1453,4 +1314,131 @@ mkLets' ::
14531314 -> Exp1
14541315 -> Exp1
14551316mkLets' [] bod = bod
1456- mkLets' (b: bs) bod = LetE b (mkLets' bs bod)
1317+ mkLets' (b: bs) bod = LetE b (mkLets' bs bod)
1318+
1319+
1320+ -- reorderExpByVariablesBoundByDataCon :: DataCon -> FunDef1 -> [[Exp1]]
1321+ -- reorderExpByVariablesBoundByDataCon dcon fundef@FunDef{funName,funBody,funTy,funArgs} initialEnv = let
1322+ -- dconVars = getVarsBoundByDconInOrder dcon funBody
1323+ -- exps = P.map (\var -> getBoundExpsVar var funBody []) dconVars
1324+ -- in exps
1325+
1326+
1327+
1328+ -- getBoundExpsVar :: Var -> Exp1 -> S.Set Exp1 -> [Exp1]
1329+ -- getBoundExpsVar var exp liveExpressions = case exp of
1330+ -- DataConE loc dcon args -> P.concatMap (\ex -> getBoundExpsVar var ex liveExpressions) args
1331+ -- VarE {} -> []
1332+ -- LitE {} -> []
1333+ -- CharE {} -> []
1334+ -- FloatE {} -> []
1335+ -- LitSymE {} -> []
1336+ -- AppE f locs args -> P.concatMap (\ex -> getBoundExpsVar var ex liveExpressions) args
1337+ -- PrimAppE f args -> P.concatMap (\ex -> getBoundExpsVar var ex liveExpressions) args
1338+ -- LetE (v, loc, ty, rhs) bod -> if v == var
1339+ -- then let freeExprs = gFreeVars rhs
1340+ -- releaseBinds = P.map (\var -> P.map (\exp -> case exp of
1341+ -- LetE (v', _, _, _) b -> if v' == var then [exp]
1342+ -- else []
1343+ -- ) S.toList liveExpressions
1344+ -- ) S.toList freeExprs
1345+
1346+ -- CaseE scrt mp ->
1347+ -- IfE a b c ->
1348+ -- MkProdE xs ->
1349+ -- ProjE i e -> error "getExpTyEnv: TODO ProjE"
1350+ -- TimeIt e ty b -> error "getExpTyEnv: TODO TimeIt"
1351+ -- WithArenaE v e -> error "getExpTyEnv: TODO WithArenaE"
1352+ -- SpawnE f locs args -> error "getExpTyEnv: TODO SpawnE"
1353+ -- SyncE -> error "getExpTyEnv: TODO SyncE"
1354+ -- Ext _ -> error "getExpTyEnv: TODO Ext"
1355+ -- MapE {} -> error "getExpTyEnv: TODO MapE"
1356+ -- FoldE {} -> error "getExpTyEnv: TODO FoldE"
1357+
1358+
1359+ -- reOrderLetExpHelper Nothing letExpOrder expr = let
1360+
1361+ -- case expr of
1362+ -- DataConE loc dcon args ->
1363+ -- VarE {} ->
1364+ -- LitE {} ->
1365+ -- CharE {} ->
1366+ -- FloatE {} ->
1367+ -- LitSymE {} ->
1368+ -- AppE f locs args ->
1369+ -- PrimAppE f args ->
1370+ -- LetE (v, loc, ty, rhs) bod ->
1371+ -- CaseE scrt mp ->
1372+ -- IfE a b c ->
1373+ -- MkProdE xs ->
1374+ -- ProjE {} -> error "reOrderLetExpHelper: TODO ProjE"
1375+ -- TimeIt {} -> error "reOrderLetExpHelper: TODO TimeIt"
1376+ -- WithArenaE {} -> error "reOrderLetExpHelper: TODO WithArenaE"
1377+ -- SpawnE {} -> error "reOrderLetExpHelper: TODO SpawnE"
1378+ -- SyncE -> error "reOrderLetExpHelper: TODO SyncE"
1379+ -- Ext {} -> error "reOrderLetExpHelper: TODO Ext"
1380+ -- MapE {} -> error "reOrderLetExpHelper: TODO MapE"
1381+ -- FoldE {} -> error "reOrderLetExpHelper: TODO FoldE"
1382+
1383+ -- reOrderLetExpHelper insertAfter@(Just var) letExpOrder expr = case expr of
1384+ -- DataConE loc dcon args -> DataConE loc dcon $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1385+ -- VarE {} -> expr
1386+ -- LitE {} -> expr
1387+ -- CharE {} -> expr
1388+ -- FloatE {} -> expr
1389+ -- LitSymE {} -> expr
1390+ -- AppE f locs args -> AppE f locs $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1391+ -- PrimAppE f args -> PrimAppE f $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1392+ -- LetE (v, loc, ty, rhs) bod -> if v == var
1393+ -- then
1394+ -- let lambda = (\l ex -> case l of
1395+ -- LetE (v', loc', ty', rhs') _ -> LetE (v', loc', ty', rhs') ex
1396+ -- _ -> error "reOrderLetExpHelper: did not expect expressions other than LetE.")
1397+ -- exp' = P.foldr lambda bod letExpOrder
1398+ -- in LetE (v, loc, ty, rhs) exp'
1399+ -- else
1400+ -- LetE (v, loc, ty, reOrderLetExpHelper insertAfter letExpOrder rhs) (reOrderLetExpHelper insertAfter letExpOrder bod)
1401+ -- CaseE scrt mp -> CaseE scrt $ P.map (\(a, b, c) -> (a, b, reOrderLetExpHelper insertAfter letExpOrder c)) mp
1402+ -- IfE a b c -> IfE (reOrderLetExpHelper insertAfter letExpOrder a) (reOrderLetExpHelper insertAfter letExpOrder b) (reOrderLetExpHelper insertAfter letExpOrder c)
1403+ -- MkProdE xs -> MkProdE $ P.map (reOrderLetExpHelper insertAfter letExpOrder) xs
1404+ -- ProjE {} -> error "reOrderLetExpHelper: TODO ProjE"
1405+ -- TimeIt {} -> error "reOrderLetExpHelper: TODO TimeIt"
1406+ -- WithArenaE {} -> error "reOrderLetExpHelper: TODO WithArenaE"
1407+ -- SpawnE {} -> error "reOrderLetExpHelper: TODO SpawnE"
1408+ -- SyncE -> error "reOrderLetExpHelper: TODO SyncE"
1409+ -- Ext {} -> error "reOrderLetExpHelper: TODO Ext"
1410+ -- MapE {} -> error "reOrderLetExpHelper: TODO MapE"
1411+ -- FoldE {} -> error "reOrderLetExpHelper: TODO FoldE"
1412+
1413+ -- TODO: This will release bindings multiple times for variables use everywhere, whreas we want to just prioritize for first use.
1414+ -- Simple solution is to refactor this into a new function and return a bool when the binds have been released.
1415+ -- check if binds have been released, if pass [] as let binds.
1416+ -- reOrderLetExpHelper insertAfter@(Just var) letExpOrder expr = case expr of
1417+ -- DataConE loc dcon args -> DataConE loc dcon $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1418+ -- VarE vv -> if vv == var
1419+ -- then
1420+ -- let lambda = (\l ex -> case l of
1421+ -- LetE (v', loc', ty', rhs') _ -> LetE (v', loc', ty', rhs') ex
1422+ -- _ -> error "reOrderLetExpHelper: did not expect expressions other than LetE.")
1423+ -- exp' = P.foldr lambda expr letExpOrder
1424+ -- in exp'
1425+ -- else
1426+ -- expr
1427+ -- LitE {} -> expr
1428+ -- CharE {} -> expr
1429+ -- FloatE {} -> expr
1430+ -- LitSymE {} -> expr
1431+ -- AppE f locs args -> AppE f locs $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1432+ -- PrimAppE f args -> PrimAppE f $ P.map (reOrderLetExpHelper insertAfter letExpOrder) args
1433+ -- LetE (v, loc, ty, rhs) bod -> LetE (v, loc, ty, reOrderLetExpHelper insertAfter letExpOrder rhs) (reOrderLetExpHelper insertAfter letExpOrder bod)
1434+ -- CaseE scrt mp -> CaseE scrt $ P.map (\(a, b, c) -> (a, b, reOrderLetExpHelper insertAfter letExpOrder c)) mp
1435+ -- IfE a b c -> IfE (reOrderLetExpHelper insertAfter letExpOrder a) (reOrderLetExpHelper insertAfter letExpOrder b) (reOrderLetExpHelper insertAfter letExpOrder c)
1436+ -- MkProdE xs -> MkProdE $ P.map (reOrderLetExpHelper insertAfter letExpOrder) xs
1437+ -- ProjE {} -> error "reOrderLetExpHelper: TODO ProjE"
1438+ -- TimeIt {} -> error "reOrderLetExpHelper: TODO TimeIt"
1439+ -- WithArenaE {} -> error "reOrderLetExpHelper: TODO WithArenaE"
1440+ -- SpawnE {} -> error "reOrderLetExpHelper: TODO SpawnE"
1441+ -- SyncE -> error "reOrderLetExpHelper: TODO SyncE"
1442+ -- Ext {} -> error "reOrderLetExpHelper: TODO Ext"
1443+ -- MapE {} -> error "reOrderLetExpHelper: TODO MapE"
1444+ -- FoldE {} -> error "reOrderLetExpHelper: TODO FoldE"
0 commit comments