git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #429 from purescript/tco-fix

TCO does not close over arguments to higher order functions

commitdb061c80f2a95596818dfa76a735be4c76921505 authorPhil Freeman <paf31@cantab.net> dateThu 29 May 2014, 12:23 (12 years ago) parentb25517e0a607a5
1 file changed+5−2
src/Language/PureScript/Optimizer/TCO.hs+5−2
src/Language/PureScript/Optimizer/TCO.hs+5−2
@@ -95,6 +95,9 @@ tco' = everywhereOnJS convert
9595 collectSelfCallArgs allArgumentValues (JSApp fn args') = collectSelfCallArgs (args' : allArgumentValues) fn
9696 collectSelfCallArgs allArgumentValues _ = allArgumentValues
9797 isSelfCall :: String -> JS -> Bool
98− isSelfCall ident (JSApp (JSVar ident') _) | ident == ident' = True
99− isSelfCall ident (JSApp fn _) = isSelfCall ident fn
98+ isSelfCall ident (JSApp (JSVar ident') args) | ident == ident' && not (any isFunction args) = True
99+ isSelfCall ident (JSApp fn args) | not (any isFunction args) = isSelfCall ident fn
100100 isSelfCall _ _ = False
101+ isFunction :: JS -> Bool
102+ isFunction (JSFunction _ _ _) = True
103+ isFunction _ = False