git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Combine inlining optimizations into a single pass (#2615)
commit5ff12867142df68c798c647216d8c0fde1ce65d1 authorPhil Freeman <paf31@cantab.net> dateSat 4 Feb 2017, 11:03 (10 years ago) parent480d7e9
1 file changed+9−17
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+9−17
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+9−17
@@ -110,7 +110,7 @@ inlineCommonValues = everywhereOnJS convert
110110 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
111111
112112inlineCommonOperators :: JS -> JS
113−inlineCommonOperators = applyAll $
113+inlineCommonOperators = everywhereOnJSTopDown $ applyAll $
114114 [ binary semiringNumber opAdd Add
115115 , binary semiringNumber opMul Multiply
116116
@@ -173,38 +173,32 @@ inlineCommonOperators = applyAll $
173173 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
174174 where
175175 binary :: (Text, PSString) -> (Text, PSString) -> BinaryOperator -> JS -> JS
176− binary dict fns op = everywhereOnJS convert
177− where
176+ binary dict fns op = convert where
178177 convert :: JS -> JS
179178 convert (JSApp ss (JSApp _ (JSApp _ fn [dict']) [x]) [y]) | isDict dict dict' && isDict fns fn = JSBinary ss op x y
180179 convert other = other
181180 binary' :: Text -> PSString -> BinaryOperator -> JS -> JS
182− binary' moduleName opString op = everywhereOnJS convert
183− where
181+ binary' moduleName opString op = convert where
184182 convert :: JS -> JS
185183 convert (JSApp ss (JSApp _ fn [x]) [y]) | isDict (moduleName, opString) fn = JSBinary ss op x y
186184 convert other = other
187185 unary :: (Text, PSString) -> (Text, PSString) -> UnaryOperator -> JS -> JS
188− unary dicts fns op = everywhereOnJS convert
189− where
186+ unary dicts fns op = convert where
190187 convert :: JS -> JS
191188 convert (JSApp ss (JSApp _ fn [dict']) [x]) | isDict dicts dict' && isDict fns fn = JSUnary ss op x
192189 convert other = other
193190 unary' :: Text -> PSString -> UnaryOperator -> JS -> JS
194− unary' moduleName fnName op = everywhereOnJS convert
195− where
191+ unary' moduleName fnName op = convert where
196192 convert :: JS -> JS
197193 convert (JSApp ss fn [x]) | isDict (moduleName, fnName) fn = JSUnary ss op x
198194 convert other = other
199195 mkFn :: Int -> JS -> JS
200− mkFn 0 = everywhereOnJS convert
201− where
196+ mkFn 0 = convert where
202197 convert :: JS -> JS
203198 convert (JSApp _ mkFnN [JSFunction s1 Nothing [_] (JSBlock s2 js)]) | isNFn C.mkFn 0 mkFnN =
204199 JSFunction s1 Nothing [] (JSBlock s2 js)
205200 convert other = other
206− mkFn n = everywhereOnJS convert
207− where
201+ mkFn n = convert where
208202 convert :: JS -> JS
209203 convert orig@(JSApp ss mkFnN [fn]) | isNFn C.mkFn n mkFnN =
210204 case collectArgs n [] fn of
@@ -223,8 +217,7 @@ inlineCommonOperators = applyAll $
223217 isNFn _ _ _ = False
224218
225219 runFn :: Int -> JS -> JS
226− runFn n = everywhereOnJS convert
227− where
220+ runFn n = convert where
228221 convert :: JS -> JS
229222 convert js = fromMaybe js $ go n [] js
230223
@@ -234,8 +227,7 @@ inlineCommonOperators = applyAll $
234227 go _ _ _ = Nothing
235228
236229 inlineNonClassFunction :: (JS -> Bool) -> (JS -> JS -> JS) -> JS -> JS
237− inlineNonClassFunction p f = everywhereOnJS convert
238− where
230+ inlineNonClassFunction p f = convert where
239231 convert :: JS -> JS
240232 convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
241233 convert other = other