git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add inlineAppliedVars optimisation

Translates the following: (function(a) { return a * a * a; })(b) Into: b * b * b

commitbc79f0694e0511504c86b5eac4ea79e35ed7925b authorBrian McKenna <brian@brianmckenna.org> dateMon 20 Apr 2015, 23:00 (12 years ago) parentc4c5830
2 files changed+10−1
src/Language/PureScript/CodeGen/JS/Optimizer.hs+2−1 src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+8
src/Language/PureScript/CodeGen/JS/Optimizer.hs+2−1
@@ -78,7 +78,8 @@ optimize' js = do
7878 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
7979 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
8080 , inlineCommonOperators
81− , inlineAppliedArrComposition ]) js
81+ , inlineAppliedArrComposition
82+ , inlineAppliedVars ]) js
8283
8384untilFixedPoint :: (Monad m, Eq a) => (a -> m a) -> a -> m a
8485untilFixedPoint f = go
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+8
@@ -19,6 +19,7 @@ module Language.PureScript.CodeGen.JS.Optimizer.Inliner (
1919 inlineOperator,
2020 inlineCommonOperators,
2121 inlineAppliedArrComposition,
22+ inlineAppliedVars,
2223 etaConvert,
2324 unThunk,
2425 evaluateIifes
@@ -246,6 +247,13 @@ inlineAppliedArrComposition = everywhereOnJS convert
246247 convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn = JSApp x [JSApp y [z]]
247248 convert other = other
248249
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+
249257isDict :: (String, String) -> JS -> Bool
250258isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
251259isDict _ _ = False