[Mono-devel-list] tailcall support in mcs
Michal Moskal
malekith at pld-linux.org
Mon Sep 15 12:52:53 EDT 2003
On Mon, Sep 15, 2003 at 05:34:59PM +0200, Paolo Molaro wrote:
> On 09/14/03 Michal Moskal wrote:
> > Is outputting tallcalls done or planned in mcs? I'm working on
> > functional language implementation. I'm generating C# (for now, later
> > I'll switch to ilasm or bytecode), so lack of tailcalls is very
> > annoying.
>
> The jit will automatically do tail recursion elimination in some cases
> (more cases can be easily added). The same code can be extended to do
> tail calls. You need to use the -O=tailc option to enable the feature.
> Help with implementing and testing the additional cases is welcome.
> I don't think adding tail call detection to mcs (or as a feature of the
> C# language) is worth it. Hopefully the MS JIT guys will catch up
> by the next version and tail call elimination will be a feature of all
> the JITs;-)
Ok, first case, mono doesn't seem to optimize callvirt (while it
optimizes regular call properly):
[malekith at roke ncc]$ mcs foo.cs
Compilation succeeded
[malekith at roke ncc]$ mono -O=all foo.exe
1999999
zsh: 12646 segmentation fault mono -O=all foo.exe
[malekith at roke ncc]$ mono --version
Mono JIT compiler version 0.26, (C) 2002, 2003 Ximian, Inc.
[malekith at roke ncc]$
class C {
int f(int n, int s)
{
if (n < 0) return s;
else return f(n - 1, s + (n % 5));
}
static int g(int n, int s)
{
if (n < 0) return s;
else return g(n - 1, s + (n % 5));
}
public static void Main () {
System.Console.WriteLine("{0}", g(1000000, 0));
System.Console.WriteLine("{0}", (new C()).f(1000000, 0));
}
}
In fact callvirt is important for me, since I compile first class
functions into objects, so local functions are objects. And
tailrecursion is most used for local functions.
--
: Michal Moskal :: http://www.kernel.pl/~malekith : GCS {C,UL}++++$ a? !tv
: When in doubt, use brute force. -- Ken Thompson : {E-,w}-- {b++,e}>+++ h
More information about the Mono-devel-list
mailing list