8

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)
Community
  • 1
  • 1
Joe Huha
  • 548
  • 3
  • 16
  • What platform are you running Mono on? (FreeBSD? OS X? Linux?) – Jack P. Aug 26 '13 at 18:59
  • Linux. 8-core AMD machine with 64G of RAM if that makes a difference. – Joe Huha Aug 26 '13 at 19:15
  • What kind of tail-recursive function do you have? Does it call itself, or does it call some other function? (or does it use continuations?) (I'm just trying to figure out what might be going wrong - because some tail-calls are actually optimized away by the F# compiler.) – Tomas Petricek Aug 26 '13 at 19:58

1 Answers1

1

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.
Jack P.
  • 11,487
  • 1
  • 29
  • 34
  • Tailc is a Mono "optimisation" option. I am using --tailcalls when running F#. I suspect that filing a bugreport would be counter-productive since Mono is well known not to get tailcalls quite right (or was until recently). But if someone knew exactly when the existing support works and when it does not, that would be great help. – Joe Huha Aug 26 '13 at 19:22
  • 3
    If you don't file a bug then how would anyone know to fix it? – 7sharp9 Jan 13 '15 at 08:05