@@ -22,8 +22,6 @@ module Language.PureScript.Optimizer.Inliner (
22 evaluateIifes
22 evaluateIifes
27import Language.PureScript.CodeGen.JS.AST
25import Language.PureScript.CodeGen.JS.AST
28import Language.PureScript.CodeGen.Common (identToJs)
26import Language.PureScript.CodeGen.Common (identToJs)
29import Language.PureScript.Optimizer.Common
27import Language.PureScript.Optimizer.Common
@@ -41,42 +39,42 @@ shouldInline (JSIndexer index val) = shouldInline index && shouldInline val
41shouldInline _ = False
39shouldInline _ = False
43etaConvert :: JS -> JS
41etaConvert :: JS -> JS
44−etaConvert = everywhere (mkT convert)
42+etaConvert = everywhereOnJS convert
46 convert :: JS -> JS
44 convert :: JS -> JS
47 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing idents block@(JSBlock body)) args)])
45 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing idents block@(JSBlock body)) args)])
48 | all shouldInline args &&
46 | all shouldInline args &&
49 not (any (`isRebound` block) (map JSVar idents)) &&
47 not (any (`isRebound` block) (map JSVar idents)) &&
50 not (any (`isRebound` block) args)
48 not (any (`isRebound` block) args)
51− = JSBlock (replaceIdents (zip idents args) body)
49+ = JSBlock (map (replaceIdents (zip idents args)) body)
52 convert js = js
50 convert js = js
54unThunk :: JS -> JS
52unThunk :: JS -> JS
55−unThunk = everywhere (mkT convert)
53+unThunk = everywhereOnJS convert
57 convert :: JS -> JS
55 convert :: JS -> JS
58 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing [] (JSBlock body)) [])]) = JSBlock body
56 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing [] (JSBlock body)) [])]) = JSBlock body
59 convert js = js
57 convert js = js
61evaluateIifes :: JS -> JS
59evaluateIifes :: JS -> JS
62−evaluateIifes = everywhere (mkT convert)
60+evaluateIifes = everywhereOnJS convert
64 convert :: JS -> JS
62 convert :: JS -> JS
65 convert (JSApp (JSFunction Nothing [] (JSBlock [JSReturn ret])) []) = ret
63 convert (JSApp (JSFunction Nothing [] (JSBlock [JSReturn ret])) []) = ret
66 convert js = js
64 convert js = js
68inlineVariables :: JS -> JS
66inlineVariables :: JS -> JS
69−inlineVariables = everywhere (mkT $ removeFromBlock go)
67+inlineVariables = everywhereOnJS $ removeFromBlock go
71 go :: [JS] -> [JS]
69 go :: [JS] -> [JS]
72 go [] = []
70 go [] = []
73 go (JSVariableIntroduction var (Just js) : sts)
71 go (JSVariableIntroduction var (Just js) : sts)
74− | shouldInline js && not (isReassigned var sts) && not (isRebound js sts) && not (isUpdated var sts) =
72+ | shouldInline js && not (any (isReassigned var) sts) && not (any (isRebound js) sts) && not (any (isUpdated var) sts) =
75− go (replaceIdent var js sts)
73+ go (map (replaceIdent var js) sts)
76 go (s:sts) = s : go sts
74 go (s:sts) = s : go sts
78inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
76inlineOperator :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
79−inlineOperator (m, op) f = everywhere (mkT convert)
77+inlineOperator (m, op) f = everywhereOnJS convert
81 convert :: JS -> JS
79 convert :: JS -> JS
82 convert (JSApp (JSApp op' [x]) [y]) | isOp op' = f x y
80 convert (JSApp (JSApp op' [x]) [y]) | isOp op' = f x y
@@ -122,7 +120,7 @@ inlineCommonOperators = applyAll
124 binary :: String -> String -> BinaryOperator -> JS -> JS
122 binary :: String -> String -> BinaryOperator -> JS -> JS
125− binary dictName opString op = everywhere (mkT convert)
123+ binary dictName opString op = everywhereOnJS convert
127 convert :: JS -> JS
125 convert :: JS -> JS
128 convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y]) | isOp fn && isOpDict dictName dict = JSBinary op x y
126 convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y]) | isOp fn && isOpDict dictName dict = JSBinary op x y
@@ -131,7 +129,7 @@ inlineCommonOperators = applyAll
131 isOp (JSIndexer (JSStringLiteral op') (JSVar prelude)) = prelude == C.prelude && opString == op'
129 isOp (JSIndexer (JSStringLiteral op') (JSVar prelude)) = prelude == C.prelude && opString == op'
132 isOp _ = False
130 isOp _ = False
133 binaryFunction :: String -> String -> BinaryOperator -> JS -> JS
131 binaryFunction :: String -> String -> BinaryOperator -> JS -> JS
134− binaryFunction dictName fnName op = everywhere (mkT convert)
132+ binaryFunction dictName fnName op = everywhereOnJS convert
136 convert :: JS -> JS
134 convert :: JS -> JS
137 convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y]) | isOp fn && isOpDict dictName dict = JSBinary op x y
135 convert (JSApp (JSApp (JSApp fn [dict]) [x]) [y]) | isOp fn && isOpDict dictName dict = JSBinary op x y
@@ -139,7 +137,7 @@ inlineCommonOperators = applyAll
139 isOp (JSAccessor fnName' (JSVar prelude)) = prelude == C.prelude && fnName == fnName'
137 isOp (JSAccessor fnName' (JSVar prelude)) = prelude == C.prelude && fnName == fnName'
140 isOp _ = False
138 isOp _ = False
141 unary :: String -> String -> UnaryOperator -> JS -> JS
139 unary :: String -> String -> UnaryOperator -> JS -> JS
142− unary dictName fnName op = everywhere (mkT convert)
140+ unary dictName fnName op = everywhereOnJS convert
144 convert :: JS -> JS
142 convert :: JS -> JS
145 convert (JSApp (JSApp fn [dict]) [x]) | isOp fn && isOpDict dictName dict = JSUnary op x
143 convert (JSApp (JSApp fn [dict]) [x]) | isOp fn && isOpDict dictName dict = JSUnary op x