git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
More inlining fixes
commitb20429d7ece7d1ff8718b9774460397ab34fe134 authorAndy Arvanitis <andyarvanitis@gmail.com> dateThu 27 Jun 2019, 21:02 (7 years ago) parent54ee44d
2 files changed+27−5
src/CodeGen/IL/Optimizer.hs+12−1 src/CodeGen/IL/Printer.hs+15−4
src/CodeGen/IL/Optimizer.hs+12−1
@@ -31,7 +31,8 @@ optimize mn il = do
3131 where
3232 tidyUp :: AST -> AST
3333 tidyUp = applyAll
34− [ collapseNestedBlocks
34+ [ ignoreUnusedResults
35+ , collapseNestedBlocks
3536 -- , collapseNestedIfs
3637 , collapseIfChecks
3738 , removeCodeAfterReturnStatements
@@ -84,6 +85,16 @@ collapseIfChecks = everywhere collapse where
8485 | prop == "otherwise" && val == "Data_Boolean" = exprs
8586 collapse exprs = exprs
8687
88+
89+ignoreUnusedResults :: AST -> AST
90+ignoreUnusedResults = everywhere $ removeFromBlock go
91+ where
92+ go :: [AST] -> [AST]
93+ go [] = []
94+ go (VariableIntroduction ss var s'@(Just s) : sts)
95+ | not $ any (everything (||) (isUsed var)) (s : sts) = (VariableIntroduction ss unusedName s') : sts
96+ go (s:sts) = s : go sts
97+
8798magicDo :: AST -> AST
8899magicDo = magicDo'' C.eff C.effDictionaries
89100
src/CodeGen/IL/Printer.hs+15−4
@@ -95,8 +95,19 @@ literals = mkPattern' match'
9595 ]
9696 match (App _ (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [x]) [y])
9797 | fnMod == dictMod
98− , dictMod == C.dataEq || dictMod == C.dataSemiring || dictMod == C.dataRing ||
99− dictMod == C.dataEuclideanRing || dictMod == C.dataHeytingAlgebra || dictMod == C.dataOrd
98+ , dictMod == C.dataEq || dictMod == C.dataOrd
99+ , Just op <- renderOp fn
100+ , Just t <- unboxType dict
101+ = mconcat <$> sequence
102+ [ return $ emit $ unbox' t x
103+ , return $ emit op
104+ , return $ emit $ unbox' t y
105+ ]
106+ match (App _ (App _ (App _ (Indexer _ (Var _ fn) (Var _ fnMod)) [Indexer _ (Var _ dict) (Var _ dictMod)]) [x]) [y])
107+ | not (isLiteral x) && not (isLiteral y)
108+ , fnMod == dictMod
109+ , dictMod == C.dataSemiring || dictMod == C.dataRing ||
110+ dictMod == C.dataEuclideanRing || dictMod == C.dataHeytingAlgebra
100111 , Just op <- renderOp fn
101112 , Just t <- unboxType dict
102113 = mconcat <$> sequence
@@ -500,13 +511,13 @@ implHeaderSource mn imports _ =
500511 "package " <> (if mn == "Main" then "main" else mn) <> "\n\n" <>
501512 "import . \"purescript\"\n" <>
502513 (if mn == "Main"
503− then "import \"purescript_ffi\"\n"
514+ then "import \"ffi\"\n"
504515 else "") <>
505516 T.concat imports <> "\n" <>
506517 "type IGNORE_UNUSED_IMPORTS = bool\n" <>
507518 "type _ = IGNORE_UNUSED_RUNTIME\n" <>
508519 (if mn == "Main"
509− then "\nconst _ = purescript_ffi.Loader\n\n"
520+ then "\nconst _ = ffi.Loader\n\n"
510521 else "\n")
511522
512523implFooterSource :: Text -> [Ident] -> Text