git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Combine function composition optimisations

They messed with each other when separate. Work really well combined.

commit58cfc6ca7b56cb358140196ab2fc86d153ab6827 authorBrian McKenna <brian@brianmckenna.org> dateTue 21 Apr 2015, 07:30 (12 years ago) parent82a1f79
2 files changed+8−12
src/Language/PureScript/CodeGen/JS/Optimizer.hs−1 src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+8−11
src/Language/PureScript/CodeGen/JS/Optimizer.hs−1
@@ -79,7 +79,6 @@ optimize' js = do
7979 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
8080 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
8181 , inlineCommonOperators
82− , inlineAppliedArrComposition
8382 , inlineAppliedVars ]) js
8483
8584untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+8−11
@@ -18,7 +18,6 @@ module Language.PureScript.CodeGen.JS.Optimizer.Inliner (
1818 inlineValues,
1919 inlineOperator,
2020 inlineCommonOperators,
21− inlineAppliedArrComposition,
2221 inlineAppliedVars,
2322 inlineArrComposition,
2423 etaConvert,
@@ -241,14 +240,6 @@ inlineCommonOperators = applyAll $
241240 go m acc (JSApp lhs [arg]) = go (m - 1) (arg : acc) lhs
242241 go _ _ _ = Nothing
243242
244−-- (f << g $ x) = f (g x)
245−inlineAppliedArrComposition :: JS -> JS
246−inlineAppliedArrComposition = everywhereOnJS convert
247− where
248− convert :: JS -> JS
249− convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn = JSApp x [JSApp y [z]]
250− convert other = other
251−
252243inlineAppliedVars :: JS -> JS
253244inlineAppliedVars = everywhereOnJS convert
254245 where
@@ -256,14 +247,20 @@ inlineAppliedVars = everywhereOnJS convert
256247 convert (JSApp (JSFunction Nothing [a] (JSBlock [JSReturn b])) [JSVar x]) = replaceIdent a (JSVar x) b
257248 convert other = other
258249
250+-- (f <<< g $ x) = f (g x)
251+-- (f <<< g) = \x -> f (g x)
259252inlineArrComposition :: (MonadSupply m) => JS -> m JS
260−inlineArrComposition js = everywhereOnJSTopDownM convert js
253+inlineArrComposition = everywhereOnJSTopDownM convert
261254 where
262255 convert :: (MonadSupply m) => JS -> m JS
263− convert (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) | isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn = do
256+ convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isArrCompose dict' fn =
257+ return $ JSApp x [JSApp y [z]]
258+ convert (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) | isArrCompose dict' fn = do
264259 arg <- freshName
265260 return $ JSFunction Nothing [arg] (JSBlock [JSReturn $ JSApp x [JSApp y [JSVar arg]]])
266261 convert other = return other
262+ isArrCompose :: JS -> JS -> Bool
263+ isArrCompose dict' fn = isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn
267264
268265isDict :: (String, String) -> JS -> Bool
269266isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName