0

I need to run some F# code with a very deep stack. This is because the Mono philosophy is that the removal of tailcalls is an optimisation, and thus does not always need to work.

I can start a thread with a large amount of stackspace, and everything works fine until I use PSeq, which is a wrapper around System.Linq.ParallelEnumerable. Then everything dies with a stack overflow. I expect the reason is that PSeq relies on the global threadpool where the threads use the default stack size.

Could someone please tell me if there is any way of making PSeq use large stacks? Many thanks.

Joe Huha
  • 548
  • 3
  • 16
  • Altering the [`TaskScheduler`](http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskscheduler.aspx) used by PLINQ [does not seem to be possible.](http://stackoverflow.com/a/5197603/1180426) – Patryk Ćwiek Aug 19 '14 at 18:00

1 Answers1

0

Apparently you can use editbin to change the default stack size for an executable. See How to change stack size for a .NET program?.

But note that many F# tail calls are rewritten by the compiler, so it doesn't matter what the runtime does. For example, here is a function in F#:

let rec zeroPresent =
    function
    | [] -> false
    | h :: t -> h = 0 || zeroPresent t

And here it is decompiled to C#. Note the while (true):

public static bool zeroPresent(FSharpList<int> _arg1)
{
    while (true)
    {
        FSharpList<int> fsharpList1 = _arg1;
        if (fsharpList1.get_TailOrNull() != null)
        {
            FSharpList<int> fsharpList2 = fsharpList1;

            FSharpList<int> tailOrNull = fsharpList2.get_TailOrNull();

            if (fsharpList2.get_HeadOrDefault() != 0)
                _arg1 = tailOrNull;
            else
                goto label_3;
        }
        else
            break;
    }
    return false;
label_3:
    return true;
}
Community
  • 1
  • 1
phoog
  • 42,068
  • 6
  • 79
  • 117
  • Many thanks for the answer. I am running under Mono/Linux. editbin appears to be a Windows utility, and Google does not seem to know of a Linux equivalent. I'll see if editing the file under Windows helps next time I have a clean tree. – Joe Huha Aug 19 '14 at 22:44