git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Fix some issues in the optimizer, so that purescript-promises can work properly.
85375f9Phil Freeman
libraries/prelude/prelude.purs+2
@@ -987,6 +987,7 @@ module IORef where
987 \ return function(f) {\
987 \ return function(f) {\
988 \ return function() {\
988 \ return function() {\
989 \ ref.value = f(ref.value);\
989 \ ref.value = f(ref.value);\
990+ \ return {};\
990 \ };\
991 \ };\
991 \ };\
992 \ };\
992 \}" :: forall s r. IORef s -> (s -> s) -> Eff (ref :: Ref | r) {}
993 \}" :: forall s r. IORef s -> (s -> s) -> Eff (ref :: Ref | r) {}
@@ -995,6 +996,7 @@ module IORef where
995 \ return function(val) {\
996 \ return function(val) {\
996 \ return function() {\
997 \ return function() {\
997 \ ref.value = val;\
998 \ ref.value = val;\
999+ \ return {};\
998 \ };\
1000 \ };\
999 \ };\
1001 \ };\
1000 \}" :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
1002 \}" :: forall s r. IORef s -> s -> Eff (ref :: Ref | r) {}
src/Language/PureScript/CodeGen/Optimize.hs+7−7
@@ -94,14 +94,13 @@ isReassigned var1 = everything (||) (mkQ False check)
94 where
94 where
95 check :: JS -> Bool
95 check :: JS -> Bool
96 check (JSFunction _ args _) | var1 `elem` args = True
96 check (JSFunction _ args _) | var1 `elem` args = True
97+ check (JSVariableIntroduction arg _) | var1 == arg = True
97 check _ = False
98 check _ = False
98
99
99isRebound :: (Data d) => JS -> d -> Bool
100isRebound :: (Data d) => JS -> d -> Bool
100−isRebound js d = any (\var -> isReassigned var d) (variablesOf js)
101+isRebound js d = any (\var -> isReassigned var d) (everything (++) (mkQ [] variablesOf) js)
101 where
102 where
102 variablesOf (JSVar var) = [var]
103 variablesOf (JSVar var) = [var]
103− variablesOf (JSAccessor _ val) = variablesOf val
104− variablesOf (JSIndexer index val) = variablesOf index ++ variablesOf val
105 variablesOf _ = []
104 variablesOf _ = []
106
105
107isUsed :: (Data d) => String -> d -> Bool
106isUsed :: (Data d) => String -> d -> Bool
@@ -163,7 +162,10 @@ etaConvert = everywhere (mkT convert)
163 where
162 where
164 convert :: JS -> JS
163 convert :: JS -> JS
165 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing idents block@(JSBlock body)) args)])
164 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing idents block@(JSBlock body)) args)])
165+ | all shouldInline args &&
166+ not (any (flip isRebound block) (map JSVar idents)) &&
167+ not (or (map (flip isRebound block) args))
166− | all shouldInline args && not (or (map (flip isRebound block) args)) = JSBlock (replaceIdents (zip idents args) body)
168+ = JSBlock (replaceIdents (zip idents args) body)
167 convert js = js
169 convert js = js
168
170
169unThunk :: JS -> JS
171unThunk :: JS -> JS
@@ -270,12 +272,10 @@ magicDo' = everywhere (mkT undo) . everywhere' (mkT convert)
270 isBind _ = False
272 isBind _ = False
271 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict effDict = True
273 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict effDict = True
272 isReturn _ = False
274 isReturn _ = False
273− isBindPoly (JSVar op) | op == identToJs (Op ">>=") = True
274 isBindPoly (JSAccessor prop (JSVar "Prelude")) | prop == identToJs (Op ">>=") = True
275 isBindPoly (JSAccessor prop (JSVar "Prelude")) | prop == identToJs (Op ">>=") = True
275 isBindPoly (JSIndexer (JSStringLiteral ">>=") (JSVar "Prelude")) = True
276 isBindPoly (JSIndexer (JSStringLiteral ">>=") (JSVar "Prelude")) = True
276 isBindPoly _ = False
277 isBindPoly _ = False
277− isRetPoly (JSVar "ret") = True
278− isRetPoly (JSAccessor "ret" (JSVar "Prelude")) = True
278+ isRetPoly (JSAccessor "$return" (JSVar "Prelude")) = True
279 isRetPoly _ = False
279 isRetPoly _ = False
280 prelude = ModuleName (ProperName "Prelude")
280 prelude = ModuleName (ProperName "Prelude")
281 effModule = ModuleName (ProperName "Eff")
281 effModule = ModuleName (ProperName "Eff")