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.
commit85375f90130c66e80b55d6d2f0150c677af30bad authorPhil Freeman <paf31@cantab.net> dateFri 7 Feb 2014, 18:26 (13 years ago) parent1893f8e
2 files changed+9−7
libraries/prelude/prelude.purs+2 src/Language/PureScript/CodeGen/Optimize.hs+7−7
libraries/prelude/prelude.purs+2
@@ -987,6 +987,7 @@ module IORef where
987987 \ return function(f) {\
988988 \ return function() {\
989989 \ ref.value = f(ref.value);\
990+ \ return {};\
990991 \ };\
991992 \ };\
992993 \}" :: forall s r. IORef s -> (s -> s) -> Eff (ref :: Ref | r) {}
@@ -995,6 +996,7 @@ module IORef where
995996 \ return function(val) {\
996997 \ return function() {\
997998 \ ref.value = val;\
999+ \ return {};\
9981000 \ };\
9991001 \ };\
10001002 \}" :: 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)
9494 where
9595 check :: JS -> Bool
9696 check (JSFunction _ args _) | var1 `elem` args = True
97+ check (JSVariableIntroduction arg _) | var1 == arg = True
9798 check _ = False
9899
99100isRebound :: (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)
101102 where
102103 variablesOf (JSVar var) = [var]
103− variablesOf (JSAccessor _ val) = variablesOf val
104− variablesOf (JSIndexer index val) = variablesOf index ++ variablesOf val
105104 variablesOf _ = []
106105
107106isUsed :: (Data d) => String -> d -> Bool
@@ -163,7 +162,10 @@ etaConvert = everywhere (mkT convert)
163162 where
164163 convert :: JS -> JS
165164 convert (JSBlock [JSReturn (JSApp (JSFunction Nothing idents block@(JSBlock body)) args)])
166− | all shouldInline args && not (or (map (flip isRebound block) args)) = JSBlock (replaceIdents (zip idents args) body)
165+ | all shouldInline args &&
166+ not (any (flip isRebound block) (map JSVar idents)) &&
167+ not (or (map (flip isRebound block) args))
168+ = JSBlock (replaceIdents (zip idents args) body)
167169 convert js = js
168170
169171unThunk :: JS -> JS
@@ -270,12 +272,10 @@ magicDo' = everywhere (mkT undo) . everywhere' (mkT convert)
270272 isBind _ = False
271273 isReturn (JSApp retPoly [effDict]) | isRetPoly retPoly && isEffDict effDict = True
272274 isReturn _ = False
273− isBindPoly (JSVar op) | op == identToJs (Op ">>=") = True
274275 isBindPoly (JSAccessor prop (JSVar "Prelude")) | prop == identToJs (Op ">>=") = True
275276 isBindPoly (JSIndexer (JSStringLiteral ">>=") (JSVar "Prelude")) = True
276277 isBindPoly _ = False
277− isRetPoly (JSVar "ret") = True
278− isRetPoly (JSAccessor "ret" (JSVar "Prelude")) = True
278+ isRetPoly (JSAccessor "$return" (JSVar "Prelude")) = True
279279 isRetPoly _ = False
280280 prelude = ModuleName (ProperName "Prelude")
281281 effModule = ModuleName (ProperName "Eff")