[m-dev.] Tail recursion warning proposal
Paul Bone
paul at bone.id.au
Thu Jan 19 15:30:05 AEDT 2017
I have proposed and partly implemented a pragma that can enable and disable
the tail recursion warning. In some ways it offers more control than
Zoltan's recent scope goal, and in other ways it offers less.
% Disable warnings
:- pragma require_tail_recursion(foo/3, [none]).
% Enable warnings
:- pragma require_tail_recursion(foo/3, [warn]).
% Make the warning an error
:- pragma require_tail_recursion(foo/3, [error]).
% Allow any type of recursion
:- pragma require_tail_recursion(foo/3, [self_or_mutual_recursion]).
% Direct recursion only
:- pragma require_tail_recursion(foo/3, [self_recursion_only]).
% Mutual recursion, but with a specific SCC (not implemented yet).
:- pragma require_tail_recursion(foo/3, [scc([bar/3, baz/2])]).
And so on, some of the options can be combined. The original discussion is
here:
http://www.mercurylang.org/list-archives/developers/2015-November/016482.html
I think that it makes sense to add an option that will make the option
conditional on whether the implementation was able to optimize the tailcall.
Since MLDS cannot currently optimize recursive calls.
:- pragma require_tail_recursion(foo/3, [optimized_tailcalls]).
This would generate a warning for recursive calls, including those in tail
position, that are not optimized to something that uses a constant stack
size (LCO, a loop, etc).
Is this okay?
Cheers.
--
Paul Bone
http://paul.bone.id.au
More information about the developers
mailing list