[m-dev.] status of --deep-profile-tail-recursion

Paul Bone paul at bone.id.au
Mon Mar 30 13:59:27 AEDT 2015

On Mon, Mar 30, 2015 at 01:05:50PM +1100, Julien Fischer wrote:
> Hi,
> --deep-profile-tail-recursion is currently turned off by default.
> There is a comment above that option (written by Paul in commit bda24d87)
> that says:
>     % We should always handle tail recursion specially in deep
>     % profiling; the option is only for benchmarks for the paper,
>     % except that this is currently broken, and not supported with
>     % coverage profiling.
> Was the brokenness mentioned in that comment fixed by the following change of
> Zoltan's,
> <http://www.mercurylang.org/list-archives/reviews/2011-July/015284.html>?

I'm not sure if this fixes it either:
    not at all,
    partially (specific cases)
    completely (general case)

I know that the borkenness pre-dates my work on deep profiling (before

> What is the status of --deep-profile-tail-recursion and --coverage-profiling?
> Coverage profiling is enabled by default so if I enable
> --deep-profile-tail-recursion do I need to disable --coverage-profiling?

That's a seperate issue and I don't remember the cause.  Yes, it probably
makes these options mutually exclusive.

Generally when I cannot use tail recursion I either use a larger stack,
or stack segments.  If both of those are unavailable I try to do something
like this:

    foldl(P, Xs, !Acc) :-
        foldl_2(P, 0, Xs, Rem, !Acc),
            Rem = [_ | _],
            foldl(P, Rem, !Acc)
            Rem = []

    foldl_2(_, _,     [],       [],  !Acc).
    foldl_2(P, Depth, [X | Xs], Rem, !Acc) :-
        ( Depth < 1000 ->
            P(X, !Acc),
            foldl_2(P, Depth + 1, Xs, !Acc)
            Rem = [X | Xs]

You have to pick the right depth limit.  In this example if I had a list of
1,000,000 items then rather than having 1,000,000 stack frames I have at
most only 1,000 + 1,000 frames.

Paul Bone

More information about the developers mailing list