git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix inliner for Data.Array.unsafeIndex (#2389)

* Fix inliner for Data.Array.unsafeIndex * Better naming in Inliner functions * Ignore dictionary name in Data.Array.unsafeIndex inlining

commit26590bb02cffce314df9b12f0e38a9d2a6675ffc authorBrandon Hamilton <brandon.hamilton@gmail.com> dateSun 16 Oct 2016, 19:19 (10 years ago) parentc0ec830
1 file changed+18−12
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+18−12
src/Language/PureScript/CodeGen/JS/Optimizer/Inliner.hs+18−12
@@ -99,15 +99,6 @@ inlineCommonValues = everywhereOnJS convert
9999 fnSubtract = (C.dataRing, C.sub)
100100 intOp ss op x y = JSBinary ss BitwiseOr (JSBinary ss op x y) (JSNumericLiteral ss (Left 0))
101101
102−inlineNonClassFunction :: (String, String) -> (JS -> JS -> JS) -> JS -> JS
103−inlineNonClassFunction (m, op) f = everywhereOnJS convert
104− where
105− convert :: JS -> JS
106− convert (JSApp _ (JSApp _ op' [x]) [y]) | isOp op' = f x y
107− convert other = other
108− isOp (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
109− isOp _ = False
110−
111102inlineCommonOperators :: JS -> JS
112103inlineCommonOperators = applyAll $
113104 [ binary semiringNumber opAdd Add
@@ -167,9 +158,9 @@ inlineCommonOperators = applyAll $
167158 , binary' C.dataIntBits C.zshr ZeroFillShiftRight
168159 , unary' C.dataIntBits C.complement BitwiseNot
169160
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.dataArray, C.unsafeIndex) $ flip (JSIndexer Nothing)
161+ , inlineNonClassFunction (isModFn (C.dataFunction, C.apply)) $ \f x -> JSApp Nothing f [x]
162+ , inlineNonClassFunction (isModFn (C.dataFunction, C.applyFlipped)) $ \x f -> JSApp Nothing f [x]
163+ , inlineNonClassFunction (isModFnWithDict (C.dataArray, C.unsafeIndex)) $ flip (JSIndexer Nothing)
173164 ] ++
174165 [ fn | i <- [0..10], fn <- [ mkFn i, runFn i ] ]
175166 where
@@ -233,6 +224,21 @@ inlineCommonOperators = applyAll $
233224 go m acc (JSApp _ lhs [arg]) = go (m - 1) (arg : acc) lhs
234225 go _ _ _ = Nothing
235226
227+ inlineNonClassFunction :: (JS -> Bool) -> (JS -> JS -> JS) -> JS -> JS
228+ inlineNonClassFunction p f = everywhereOnJS convert
229+ where
230+ convert :: JS -> JS
231+ convert (JSApp _ (JSApp _ op' [x]) [y]) | p op' = f x y
232+ convert other = other
233+
234+ isModFn :: (String, String) -> JS -> Bool
235+ isModFn (m, op) (JSAccessor _ op' (JSVar _ m')) = m == m' && op == op'
236+ isModFn _ _ = False
237+
238+ isModFnWithDict :: (String, String) -> JS -> Bool
239+ isModFnWithDict (m, op) (JSApp _ (JSAccessor _ op' (JSVar _ m')) [(JSVar _ _)]) = m == m' && op == op'
240+ isModFnWithDict _ _ = False
241+
236242-- (f <<< g $ x) = f (g x)
237243-- (f <<< g) = \x -> f (g x)
238244inlineFnComposition :: (MonadSupply m) => JS -> m JS