@@ -20,11 +20,13 @@ module Language.PureScript.CodeGen.JS.Optimizer.Inliner (
2020 inlineCommonOperators,
2121 inlineAppliedArrComposition,
2222 inlineAppliedVars,
23+ inlineArrComposition,
2324 etaConvert,
2425 unThunk,
2526 evaluateIifes
2627) where
2728
29+import Control.Monad.Supply.Class (MonadSupply, freshName)
2830import Data.Maybe (fromMaybe)
2931
3032import Language.PureScript.CodeGen.JS.AST
@@ -254,6 +256,15 @@ inlineAppliedVars = everywhereOnJS convert
254256 convert (JSApp (JSFunction Nothing [a] (JSBlock [JSReturn b])) [JSVar x]) = replaceIdent a (JSVar x) b
255257 convert other = other
256258
259+inlineArrComposition :: (MonadSupply m) => JS -> m JS
260+inlineArrComposition js = everywhereOnJSTopDownM convert js
261+ where
262+ convert :: (MonadSupply m) => JS -> m JS
263+ convert (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) | isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn = do
264+ arg <- freshName
265+ return $ JSFunction Nothing [arg] (JSBlock [JSReturn $ JSApp x [JSApp y [JSVar arg]]])
266+ convert other = return other
267+
257268isDict :: (String, String) -> JS -> Bool
258269isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
259270isDict _ _ = False