I have a .NET 4.0 application that makes heavy use of tail recursion (programmed in F#). It runs fine on the .NET VM, but it runs out of stack on Mono-3.0.1.
I've tried running with mono --optimize=tailc
but that doesn't seem to change anything.
Is there some way to force mono to eliminate tail calls? Is there some way to increase the maximum stack size in mono?
Since each function call consumes both additional space and additional time, the removal of tail recursion by the optimizer increases the performance of a function significantly — and it eliminates the possibility that the recursive function could overflow memory as it tries to remember variable values in each ...
F# is a functional-first language and its compiler is designed to provide tail-call optimization if possible. The most efficient way is to turn the recursive function into a function with a loop.
Unfortunately, the C# compiler doesn't support tail recursion, which is a pity, since the CLR supports it.
There is a very similar more recent question with helpful answers: Stack size under Mono
As Robert Harvey already pointed out in the comments, Mono has broken/incomplete tail call support for F# (bug 476785: Tail call support in F#). Fix for this problem is on Mono's runtime ongoing projects list.
Stack size can be increased either using System.Threading.Thread
constructor or in the PE header. The System.Threading.Thread
way does not work in Mono, though. For changing the PE, you'll probably need MS Visual Studio, since there may be no alternative to its editbin.exe /stack
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With