git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add inlineAppliedVars optimisation
bc79f06Brian McKenna
src/Language/PureScript/CodeGen/JS/Optimizer.hs+2−1
@@ -78,7 +78,8 @@ optimize' js = do
78 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
78 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
79 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
79 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
80 , inlineCommonOperators
80 , inlineCommonOperators
81− , inlineAppliedArrComposition ]) js
81+ , inlineAppliedArrComposition
82+ , inlineAppliedVars ]) js
82
83
83untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
84untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
84untilFixedPoint f = go
85untilFixedPoint f = go
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+8
@@ -19,6 +19,7 @@ module Language.PureScript.CodeGen.JS.Optimizer.Inliner (
19 inlineOperator,
19 inlineOperator,
20 inlineCommonOperators,
20 inlineCommonOperators,
21 inlineAppliedArrComposition,
21 inlineAppliedArrComposition,
22+ inlineAppliedVars,
22 etaConvert,
23 etaConvert,
23 unThunk,
24 unThunk,
24 evaluateIifes
25 evaluateIifes
@@ -246,6 +247,13 @@ inlineAppliedArrComposition = everywhereOnJS convert
246 convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn = JSApp x [JSApp y [z]]
247 convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn = JSApp x [JSApp y [z]]
247 convert other = other
248 convert other = other
248
249
250+inlineAppliedVars :: JS -> JS
251+inlineAppliedVars = everywhereOnJS convert
252+ where
253+ convert :: JS -> JS
254+ convert (JSApp (JSFunction Nothing [a] (JSBlock [JSReturn b])) [JSVar x]) = replaceIdent a (JSVar x) b
255+ convert other = other
256+
249isDict :: (String, String) -> JS -> Bool
257isDict :: (String, String) -> JS -> Bool
250isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
258isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
251isDict _ _ = False
259isDict _ _ = False