git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix inlining for apply operators
c6174d5Gary Burgess
src/Language/PureScript/CodeGen/JS/Optimizer.hs−6
@@ -34,7 +34,6 @@ import Language.PureScript.CodeGen.JS.Optimizer.MagicDo
34import Language.PureScript.CodeGen.JS.Optimizer.TCO
34import Language.PureScript.CodeGen.JS.Optimizer.TCO
35import Language.PureScript.CodeGen.JS.Optimizer.Unused
35import Language.PureScript.CodeGen.JS.Optimizer.Unused
36import Language.PureScript.Options
36import Language.PureScript.Options
37−import qualified Language.PureScript.Constants as C
38
37
39-- |
38-- |
40-- Apply a series of optimizer passes to simplified Javascript code
39-- Apply a series of optimizer passes to simplified Javascript code
@@ -49,11 +48,6 @@ optimize' js = do
49 opts <- ask
48 opts <- ask
50 js' <- untilFixedPoint (inlineFnComposition . tidyUp . applyAll
49 js' <- untilFixedPoint (inlineFnComposition . tidyUp . applyAll
51 [ inlineCommonValues
50 [ inlineCommonValues
52− , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp Nothing f [x]
53− , inlineOperator (C.dataFunction, C.apply) $ \f x -> JSApp Nothing f [x]
54− , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp Nothing f [x]
55− , inlineOperator (C.dataFunction, C.applyFlipped) $ \x f -> JSApp Nothing f [x]
56− , inlineOperator (C.dataArrayUnsafe, C.unsafeIndex) $ flip (JSIndexer Nothing)
57 , inlineCommonOperators
51 , inlineCommonOperators
58 ]) js
52 ]) js
59 untilFixedPoint (return . tidyUp) . tco opts . magicDo opts $ js'
53 untilFixedPoint (return . tidyUp) . tco opts . magicDo opts $ js'
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+7−4
@@ -4,7 +4,6 @@
4module Language.PureScript.CodeGen.JS.Optimizer.Inliner
4module Language.PureScript.CodeGen.JS.Optimizer.Inliner
5 ( inlineVariables
5 ( inlineVariables
6 , inlineCommonValues
6 , inlineCommonValues
7− , inlineOperator
8 , inlineCommonOperators
7 , inlineCommonOperators
9 , inlineFnComposition
8 , inlineFnComposition
10 , etaConvert
9 , etaConvert
@@ -100,13 +99,13 @@ inlineCommonValues = everywhereOnJS convert
100 fnSubtract = (C.dataRing, C.sub)
99 fnSubtract = (C.dataRing, C.sub)
101 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
100 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
102
101
103−inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
102+inlineNonClassFunction :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
104−inlineOperator (m, op) f = everywhereOnJS convert
103+inlineNonClassFunction (m, op) f = everywhereOnJS convert
105 where
104 where
106 convert :: JS -> JS
105 convert :: JS -> JS
107 convert (JSApp _ (JSApp _ op' [x]) [y]) | isOp op' = f x y
106 convert (JSApp _ (JSApp _ op' [x]) [y]) | isOp op' = f x y
108 convert other = other
107 convert other = other
109− isOp (JSIndexer _ (JSStringLiteral _ op') (JSVar _ m')) = m == m' && op == op'
108+ isOp (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
110 isOp _ = False
109 isOp _ = False
111
110
112inlineCommonOperators :: JS -> JS
111inlineCommonOperators :: JS -> JS
@@ -167,6 +166,10 @@ inlineCommonOperators = applyAll $
167 , binary' C.dataIntBits C.shr ShiftRight
166 , binary' C.dataIntBits C.shr ShiftRight
168 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
167 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
169 , unary' C.dataIntBits C.complement BitwiseNot
168 , unary' C.dataIntBits C.complement BitwiseNot
169+
170+ , inlineNonClassFunction (C.dataFunction, C.apply) $ \f x -> JSApp Nothing f [x]
171+ , inlineNonClassFunction (C.dataFunction, C.applyFlipped) $ \x f -> JSApp Nothing f [x]
172+ , inlineNonClassFunction (C.dataArrayUnsafe, C.unsafeIndex) $ flip (JSIndexer Nothing)
170 ] ++
173 ] ++
171 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
174 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
172 where
175 where