git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Remove (<<<)/(>>>) inlining. Move `pure` inlining to `magicDo`.
681dd8bjoneshf
src/Language/PureScript/Constants.hs−6
@@ -23,12 +23,6 @@ module Language.PureScript.Constants where
23(#) :: String
23(#) :: String
24(#) = "#"
24(#) = "#"
25
25
26−(<<<) :: String
27−(<<<) = "<<<"
28−
29−(>>>) :: String
30−(>>>) = ">>>"
31−
32(<>) :: String
26(<>) :: String
33(<>) = "<>"
27(<>) = "<>"
34
28
src/Language/PureScript/Optimizer.hs−2
@@ -61,8 +61,6 @@ optimize opts | optionsNoOptimizations opts = id
61 , etaConvert
61 , etaConvert
62 , evaluateIifes
62 , evaluateIifes
63 , inlineVariables
63 , inlineVariables
64− , inlinePure
65− , inlineCompose
66 , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
64 , inlineOperator (C.prelude, (C.$)) $ \f x -> JSApp f [x]
67 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
65 , inlineOperator (C.prelude, (C.#)) $ \x f -> JSApp f [x]
68 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
66 , inlineOperator (C.preludeUnsafe, C.unsafeIndex) $ flip JSIndexer
src/Language/PureScript/Optimizer/Inliner.hs−29
@@ -15,8 +15,6 @@
15
15
16module Language.PureScript.Optimizer.Inliner (
16module Language.PureScript.Optimizer.Inliner (
17 inlineVariables,
17 inlineVariables,
18− inlinePure,
19− inlineCompose,
20 inlineOperator,
18 inlineOperator,
21 inlineCommonOperators,
19 inlineCommonOperators,
22 etaConvert,
20 etaConvert,
@@ -30,7 +28,6 @@ import Language.PureScript.CodeGen.JS.AST
30import Language.PureScript.CodeGen.Common (identToJs)
28import Language.PureScript.CodeGen.Common (identToJs)
31import Language.PureScript.Optimizer.Common
29import Language.PureScript.Optimizer.Common
32import Language.PureScript.Names
30import Language.PureScript.Names
33−import Language.PureScript.Supply (freshName, evalSupply)
34
31
35import qualified Language.PureScript.Constants as C
32import qualified Language.PureScript.Constants as C
36
33
@@ -74,32 +71,6 @@ evaluateIifes = everywhereOnJS convert
74 convert (JSApp (JSFunction Nothing [] (JSBlock [JSReturn ret])) []) = ret
71 convert (JSApp (JSFunction Nothing [] (JSBlock [JSReturn ret])) []) = ret
75 convert js = js
72 convert js = js
76
73
77−inlinePure :: JS -> JS
78−inlinePure = everywhereOnJS convert
79− where
80− convert :: JS -> JS
81− convert (JSApp (JSApp p eff) [js]) | isPure p && isEff eff = JSFunction Nothing [] (JSBlock [JSReturn js])
82− convert other = other
83− isPure (JSAccessor f (JSVar prelude)) = (f == C.pure' || f == C.return) && prelude == C.prelude
84− isPure _ = False
85− isEff [JSApp (JSAccessor app (JSVar eff)) _] = app == C.applicativeEffDictionary && eff == C.eff
86− isEff _ = False
87−
88−inlineCompose :: JS -> JS
89−inlineCompose = everywhereOnJS convert
90− where
91− convert :: JS -> JS
92− convert (JSApp (JSApp comp [f]) [g]) | isBackwardComp comp = JSFunction Nothing [var] (JSBlock [JSReturn (JSApp f [JSApp g [JSVar var]])])
93− convert (JSApp (JSApp comp [f]) [g]) | isForwardComp comp = JSFunction Nothing [var] (JSBlock [JSReturn (JSApp g [JSApp f [JSVar var]])])
94− convert other = other
95− var = evalSupply 1 freshName
96− isBackwardComp (JSApp (JSIndexer (JSStringLiteral comp) (JSVar prelude)) semi) = comp == (C.<<<) && prelude == C.prelude && isSemi semi
97− isBackwardComp _ = False
98− isForwardComp (JSApp (JSIndexer (JSStringLiteral comp) (JSVar prelude)) semi) = comp == (C.>>>) && prelude == C.prelude && isSemi semi
99− isForwardComp _ = False
100− isSemi [JSApp (JSAccessor semi (JSVar prelude)) _] = semi == C.semigroupoidArr && prelude == C.prelude
101− isSemi _ = False
102−
103inlineVariables :: JS -> JS
74inlineVariables :: JS -> JS
104inlineVariables = everywhereOnJS $ removeFromBlock go
75inlineVariables = everywhereOnJS $ removeFromBlock go
105 where
76 where
src/Language/PureScript/Optimizer/MagicDo.hs+9
@@ -57,6 +57,8 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
57 convert :: JS -> JS
57 convert :: JS -> JS
58 -- Desugar return
58 -- Desugar return
59 convert (JSApp (JSApp ret [val]) []) | isReturn ret = val
59 convert (JSApp (JSApp ret [val]) []) | isReturn ret = val
60+ -- Desugar pure
61+ convert (JSApp (JSApp pure' [val]) []) | isPure pure' = val
60 -- Desugar >>
62 -- Desugar >>
61 convert (JSApp (JSApp bind [m]) [JSFunction Nothing ["_"] (JSBlock js)]) | isBind bind && isJSReturn (last js) =
63 convert (JSApp (JSApp bind [m]) [JSFunction Nothing ["_"] (JSBlock js)]) | isBind bind && isJSReturn (last js) =
62 let JSReturn ret = last js in
64 let JSReturn ret = last js in
@@ -78,6 +80,9 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
78 -- Check if an expression represents a monomorphic call to return for the Eff monad
80 -- Check if an expression represents a monomorphic call to return for the Eff monad
79 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict C.monadEffDictionary effDict = True
81 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict C.monadEffDictionary effDict = True
80 isReturn _ = False
82 isReturn _ = False
83+ -- Check if an expression represents a monomorphic call to pure for the Eff applicative
84+ isPure (JSApp purePoly [effDict]) | isPurePoly purePoly && isEffDict C.applicativeEffDictionary effDict = True
85+ isPure _ = False
81 -- Check if an expression represents the polymorphic >>= function
86 -- Check if an expression represents the polymorphic >>= function
82 isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && prop == identToJs (Op (C.>>=))
87 isBindPoly (JSAccessor prop (JSVar prelude)) = prelude == C.prelude && prop == identToJs (Op (C.>>=))
83 isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && bind == (C.>>=)
88 isBindPoly (JSIndexer (JSStringLiteral bind) (JSVar prelude)) = prelude == C.prelude && bind == (C.>>=)
@@ -86,6 +91,10 @@ magicDo' = everywhereOnJS undo . everywhereOnJSTopDown convert
86 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
91 isRetPoly (JSAccessor returnEscaped (JSVar prelude)) = prelude == C.prelude && returnEscaped == C.returnEscaped
87 isRetPoly (JSIndexer (JSStringLiteral return') (JSVar prelude)) = prelude == C.prelude && return' == C.return
92 isRetPoly (JSIndexer (JSStringLiteral return') (JSVar prelude)) = prelude == C.prelude && return' == C.return
88 isRetPoly _ = False
93 isRetPoly _ = False
94+ -- Check if an expression represents the polymorphic pure function
95+ isPurePoly (JSAccessor pure' (JSVar prelude)) = prelude == C.prelude && pure' == C.pure'
96+ isPurePoly (JSIndexer (JSStringLiteral pure') (JSVar prelude)) = prelude == C.prelude && pure' == C.pure'
97+ isPurePoly _ = False
89 -- Check if an expression represents a function in the Ef module
98 -- Check if an expression represents a function in the Ef module
90 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
99 isEffFunc name (JSAccessor name' (JSVar eff)) = eff == C.eff && name == name'
91 isEffFunc _ _ = False
100 isEffFunc _ _ = False