git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #1428 from purescript/1427-fix-composition-inline
4f4e6ecGary Burgess
src/Language/PureScript/CodeGen/JS/Optimizer.hs+1−1
@@ -66,7 +66,7 @@ optimize js = do
66optimize' :: (Monad m, MonadReader Options m, Applicative m, MonadSupply m) => JS -> m JS
66optimize' :: (Monad m, MonadReader Options m, Applicative m, MonadSupply m) => JS -> m JS
67optimize' js = do
67optimize' js = do
68 opts <- ask
68 opts <- ask
69− untilFixedPoint (inlineArrComposition . applyAll
69+ untilFixedPoint (inlineFnComposition . applyAll
70 [ collapseNestedBlocks
70 [ collapseNestedBlocks
71 , collapseNestedIfs
71 , collapseNestedIfs
72 , tco opts
72 , tco opts
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+9−9
@@ -20,7 +20,7 @@ module Language.PureScript.CodeGen.JS.Optimizer.Inliner (
20 inlineValues,
20 inlineValues,
21 inlineOperator,
21 inlineOperator,
22 inlineCommonOperators,
22 inlineCommonOperators,
23− inlineArrComposition,
23+ inlineFnComposition,
24 etaConvert,
24 etaConvert,
25 unThunk,
25 unThunk,
26 evaluateIifes
26 evaluateIifes
@@ -244,18 +244,18 @@ inlineCommonOperators = applyAll $
244
244
245-- (f <<< g $ x) = f (g x)
245-- (f <<< g $ x) = f (g x)
246-- (f <<< g) = \x -> f (g x)
246-- (f <<< g) = \x -> f (g x)
247−inlineArrComposition :: (Applicative m, MonadSupply m) => JS -> m JS
247+inlineFnComposition :: (Applicative m, MonadSupply m) => JS -> m JS
248−inlineArrComposition = everywhereOnJSTopDownM convert
248+inlineFnComposition = everywhereOnJSTopDownM convert
249 where
249 where
250 convert :: (MonadSupply m) => JS -> m JS
250 convert :: (MonadSupply m) => JS -> m JS
251− convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isArrCompose dict' fn =
251+ convert (JSApp (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) [z]) | isFnCompose dict' fn =
252 return $ JSApp x [JSApp y [z]]
252 return $ JSApp x [JSApp y [z]]
253− convert (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) | isArrCompose dict' fn = do
253+ convert (JSApp (JSApp (JSApp fn [dict']) [x]) [y]) | isFnCompose dict' fn = do
254 arg <- freshName
254 arg <- freshName
255 return $ JSFunction Nothing [arg] (JSBlock [JSReturn $ JSApp x [JSApp y [JSVar arg]]])
255 return $ JSFunction Nothing [arg] (JSBlock [JSReturn $ JSApp x [JSApp y [JSVar arg]]])
256 convert other = return other
256 convert other = return other
257− isArrCompose :: JS -> JS -> Bool
257+ isFnCompose :: JS -> JS -> Bool
258− isArrCompose dict' fn = isDict semigroupoidArr dict' && isPreludeFn (C.<<<) fn
258+ isFnCompose dict' fn = isDict semigroupoidFn dict' && (isPreludeFn (C.<<<) fn || isPreludeFn (C.compose) fn)
259
259
260isDict :: (String, String) -> JS -> Bool
260isDict :: (String, String) -> JS -> Bool
261isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
261isDict (moduleName, dictName) (JSAccessor x (JSVar y)) = x == dictName && y == moduleName
@@ -314,5 +314,5 @@ boundedBoolean = (C.prelude, C.boundedBoolean)
314booleanAlgebraBoolean :: (String, String)
314booleanAlgebraBoolean :: (String, String)
315booleanAlgebraBoolean = (C.prelude, C.booleanAlgebraBoolean)
315booleanAlgebraBoolean = (C.prelude, C.booleanAlgebraBoolean)
316
316
317−semigroupoidArr :: (String, String)
317+semigroupoidFn :: (String, String)
318−semigroupoidArr = (C.prelude, C.semigroupoidArr)
318+semigroupoidFn = (C.prelude, C.semigroupoidFn)
src/Language/PureScript/Constants.hs+5−2
@@ -89,6 +89,9 @@ unsafeIndex = "unsafeIndex"
89(<<<) :: String
89(<<<) :: String
90(<<<) = "<<<"
90(<<<) = "<<<"
91
91
92+compose :: String
93+compose = "compose"
94+
92-- Functions
95-- Functions
93
96
94negate :: String
97negate :: String
@@ -235,8 +238,8 @@ booleanAlgebraBoolean = "booleanAlgebraBoolean"
235semigroupString :: String
238semigroupString :: String
236semigroupString = "semigroupString"
239semigroupString = "semigroupString"
237
240
238−semigroupoidArr :: String
241+semigroupoidFn :: String
239−semigroupoidArr = "semigroupoidArr"
242+semigroupoidFn = "semigroupoidFn"
240
243
241-- Generic Deriving
244-- Generic Deriving
242
245