Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailcalls in Mono

I have some code in F# that works fine under .net but overflows the stack under Mono. A related issue is that it seems to do so long before the stack space supposedly available to it runs out (it is started with System.Threading.Thread (ts, 1000000000)). As far as I can tell, the fold it dies in is tail-recursive and the stack trace looks as if tail-optimization is not being done. I am running 3.2.1 with --optimize=tailc.

Does somebody please know exactly what kinds of tail calls remove the calling stack and which do not? Or alternatively how to allocate more stack? Many thanks.

I am aware of Tailcall elimination in Mono

EDIT: here is an outline of the code as requested in the comments. It is a part of a fold over a large data structure, but the failing stacktrace has just mapk and myfold on it.

let rec myfold f x k =

   let rec mapk xs k =
    match xs with
     [] -> k []
   | x::xs -> mapk xs (fun xs' -> myfold f x (fun x' -> (x' :: xs') |> k))

... 

mapk (...) ( ... >> k)
like image 964
Joe Huha Avatar asked Aug 26 '13 18:08

Joe Huha


1 Answers

As far as I know, --optimize=tailc isn't a supported F# compiler flag.

I don't think there's a way to enable/disable tailcall-optimization support in Mono (from the command-line, anyway); the F# compiler flag to enable tail-call optimizations is --tailcalls+, but according to Compiler Options (F#) that's on by default.

I think your best choices to get this resolved are:

  • File a bug report with Xamarin
  • Go on the #monodev IRC channel (on irc.gnome.org) and see if one of the developers/contributors there can help you out.
like image 127
Jack P. Avatar answered Nov 15 '22 06:11

Jack P.