@@ -18,6 +18,7 @@ module Language.PureScript.CodeGen.JS.Optimizer.Inliner (
1818 inlineValues,
1919 inlineOperator,
2020 inlineCommonOperators,
21+ inlineAppliedArrComposition,
2122 etaConvert,
2223 unThunk,
2324 evaluateIifes
@@ -31,6 +32,10 @@ import Language.PureScript.Names
3132import Language.PureScript.CodeGen.JS.Optimizer.Common
3233import qualified Language.PureScript.Constants as C
3334
35+-- TODO: Potential bug:
36+-- Shouldn't just inline this case: { var x = 0; x.toFixed(10); }
37+-- Needs to be: { 0..toFixed(10); }
38+-- Probably needs to be fixed in pretty-printer instead.
3439shouldInline :: JS -> Bool
3540shouldInline (JSVar _) = True
3641shouldInline (JSNumericLiteral _) = True
@@ -233,6 +238,14 @@ inlineCommonOperators = applyAll $
233238 go m acc (JSApp lhs [arg]) = go (m - 1) (arg : acc) lhs
234239 go _ _ _ = Nothing
235240
241+-- (f << g $ x) = f (g x)
242+inlineAppliedArrComposition :: JS -> JS
243+inlineAppliedArrComposition = everywhereOnJS convert
244+ where
245+ convert :: JS -> JS
246+ 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+
236249isDict :: (String, String) -> JS -> Bool
237250isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
238251isDict _ _ = False
@@ -292,3 +305,6 @@ latticeBoolean = (C.prelude, C.latticeBoolean)
292305
293306complementedLatticeBoolean :: (String, String)
294307complementedLatticeBoolean = (C.prelude, C.complementedLatticeBoolean)
308+
309+semigroupoidArr :: (String, String)
310+semigroupoidArr = (C.prelude, C.semigroupoidArr)