[m-dev.] [m-users.] Tail recursion optimisation
Zoltan Somogyi
zoltan.somogyi at runbox.com
Mon May 18 19:28:13 AEST 2026
On Mon, 18 May 2026 19:19:13 +1000, Julien Fischer <jfischer at opturion.com> wrote:
> When this feature was first introduced, my suggestion was that in
> grades that *cannot*
> support tail recursion, we change the meaning of "error" in the pragma to emit a
> warning or information message to that effect. That is less complicated than
> adding the extra dimension above.
But I have already implemented the extra dimension, and I am now just testing it.
And warnings wouldn't work seamlessly, as they may require undoing --halt-at-warn.
Informational would work.
In fact, the bootcheck finished ok while writing this.
> We could include some words about how to ameliorate the non-constant stack
> usage in grades that don't support tail recursion (e.g. increase the stack size,
> using a .stseg grade etc)
Those avoid crashes, but they still have bad performance for huge inputs,
due to trashing the data cache.
> and also mention that the program may need
> to be profiled /
> debugged with smaller inputs.
That works only if the correctness/performance problem shows up for smaller inputs.
Granted, it usually does.
I would much rather recommend two-level loops, since they are a more general solution.
Zoltan.
More information about the developers
mailing list