[m-dev.] New pragmas for tail recursion warnings
paul at bone.id.au
Fri Nov 13 17:08:20 AEDT 2015
Recently Ian improvement to warnings about tail recursive code, I removed
warnings for calls that are obviously non-tail recursive. Such as for the
first recursive call in something like qsort.
What I'd like to do next to make these warnings more usable by adding two to
four pragmas to control the warnings on a finer level. The motivation for
this is as follows. A programmer enables this warning for their whole
project or module, but they have some code that isn't, and will never be,
tail recursive. So they should be able to use a pragma to disable this
warning for this one procedure.
Likewise, another programmer does not enable this warning for their project
or module. But they have a procedure that they know may be called with very
large inputs, so it's important that that procedure is tail recursive. They
should be able to enable the warning for that procedure.
What I'd like to have reviewed at this stage are the names and syntax of the
% This pragma works on all procedures of a given predicate/function.
:- pragma no_warn_tail_recursion(NAME/ARITY).
% This pragma works on a single procedure.
:- pragma no_warn_tail_recursion(NAME(ARG_MODES*)).
:- pragma warn_tail_recursion(NAME/ARITY).
:- pragma warn_tail_recursion(NAME(ARG_MODES*)).
What I had also considered, but now I think it isn't useful and may
overcomplicate things is using four pragmas to enable this separately for
I considered this because the MLDS backend doesn't currently support mutual
recursion, so users may want to disable that warning. Even when I implement
mutual recursion (which we seem to agree should be done) it won't initially
be supported for Java or C# (I don't know about Erlang, maybe Erlang has
native support). So perhaps warnings for mutual recursion should be enabled
only with a command line option. Warnings for mutual recursion in the MLDS
grades aren't currently supported at all.
So my questions are:
Does anyone see a problem with the names or syntax of these pragmas?
Does anyone want to enable warnings for mutually recursive
More information about the developers