4

given that CLR supports tail call optimization I was wondering if Mono, and consequently Ironpython running on Mono has support for TCO ?

srean
  • 2,578
  • 18
  • 18
  • You can test this easily enough. Just set up an infinite tail-call recursion and let it run; either it explodes or it doesn't. – Glenn Maynard Oct 31 '10 at 04:34
  • If you can run a simple `def f(): return f()` and memory usage stays constant, you know that at least some basic level of tail call optimization is happening, though of course that doesn't tell you its limitations. – Glenn Maynard Oct 31 '10 at 04:47
  • possible duplicate of [Does the mono runtime already handle tail call optimisation as required by the IL spec?](http://stackoverflow.com/questions/3816148/does-the-mono-runtime-already-handle-tail-call-optimisation-as-required-by-the-il) – tzot Oct 31 '10 at 10:54
  • @ΤΖΩΤΖΙΟΥ My interest is more on Ironpython running on Mono rather than Mono per se – srean Oct 31 '10 at 18:31
  • Duplicate question: http://stackoverflow.com/questions/3816148/does-the-mono-runtime-already-handle-tail-call-optimisation-as-required-by-the-il – skolima Oct 31 '10 at 10:04
  • Not quite, my question was with regards to _Ironpython_ running on Mono rather than on Mono per se – srean Oct 31 '10 at 18:33
  • If Mono does not support TCO, how can IronPython on Mono support it if it's a JIT feature? And if you're asking whether IronPython compiler uses the .tailcall prefix - that's not a Mono-related question. – skolima Nov 01 '10 at 07:54
  • I was addressing your concern that my question is a duplicate. My question was wrt Ironpython on Mono, whereas the dup that you pointed was concerned with Mono only. I was unaware of the status of Mono wrt tail recursion and the Ironpython issue depends on it but is not equivalent to it. By following @Marcelo's leads I came to know that Mono has some limited support for TCO. The question whether Ironpython makes use of that limited support remains open. Hope that clears things a bit, and no my question is/was not a duplicate. – srean Nov 01 '10 at 13:09
  • Unfortunately, only cases in which Mono "supports" TCO is when the F# compiler converts a tail call to a while loop. So no special runtime support is needed then. In more complex cases, when the compiler uses the .tailcall prefix, Mono ignores it and fails with a StackOverflowException. – skolima Nov 02 '10 at 09:26

1 Answers1

4

I can't give a definitive answer, but there is ample evidence in forums (e.g., here) that because Mono doesn't use a callee-pops-arguments calling convention, it can't (easily) support tail calls. There is a couple of unresolved bugs, here and here, indicating that F# is still waiting for this.

Marcelo Cantos
  • 181,030
  • 38
  • 327
  • 365
  • Hi @Marcelo I haven't accepted an answer yet just in case an authoritative answer comes along. I suspect your answer is going to be as definitive as it will ever get in the near future. Is there a SO convention for acceptance in such situations, I am new here so I do not know. – srean Nov 01 '10 at 04:04
  • There are no hard-and-fast rules. Just give it a while and then click the tick when you think you've seen the best answer. – Marcelo Cantos Nov 01 '10 at 06:10