@@ -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,29 +240,27 @@ 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
255246 convert :: JS -> JS
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
0 commit comments