[m-rev.] for review: simplify require_tail_recursion pragmas ...

Julien Fischer jfischer at opturion.com
Tue Jun 9 02:07:11 AEST 2026


On Mon, 8 Jun 2026 at 15:25, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:

> Simplify require_tail_recursion pragmas.
>
> Delete the "none" option from require_tail_recursion pragmas, which was
> completely different from, and incompatible with, all the other options
> of that pragma. Replace it with a new single-purpose pragma named
> "disable_non_tail_recursion_reports".
>
> Make the --warn-non-tail-recursion option more useful. Until now,
> it merely gave permission to the compiler to report the diagnostics
> generated for predicates with require_tail_recursion pragmas,
> so a programmer who wanted such diagnostics had to specify *both*
> a pragma and an option. Change this so that the compiler generates
> such diagnostics if *either* the pragma or the option is given.
> (The disable_non_tail_recursion_reports pragma, if given,
> does override the option).

...

> compiler/mercury_compile_mlds_back_end.m:
>     Always invoke mark_tail_calls.m; do not depend on the value of an option
>     (which was always set by default anyway at any opt level above 0).
>     Rename the predicate involved accordinly.

s/accordinly/accordingly/

>
> compiler/mercury_compile_llds_back_end.m:
>     Perform the same rename.
>
> tests/invalid/require_tailrec_1.err_exp:
> tests/invalid/require_tailrec_1.err_exp2:
> tests/invalid/require_tailrec_1.err_exp3:
> tests/invalid/require_tailrec_1.m:
> tests/invalid/require_tailrec_2.err_exp:
> tests/invalid/require_tailrec_2.err_exp2:
> tests/invalid/require_tailrec_2.err_exp3:
> tests/invalid/require_tailrec_2.m:
>     Replace the original three test cases of the require_tail_recursion pragma
>     with these two.
>
>     - require_tailrec_1 tests the situation in which all diagnostics
>       are requested by pragmas, while
>     - require_tailrec_2 tests the situation in which all diagnostics
>       are requested by the "--warn-non-tail-recursion self-and-mutual"
>       option (which some then disabled by the new pragma).

s/which/while/

I think these test cases would be better named:

- require_tailrec_pragma
- require_tailrec_option

>     Their contents contain the exact same code on the exact same lines.


...

> diff --git a/tests/invalid/require_tailrec_1.m b/tests/invalid/require_tailrec_1.m
> index fb07cc863..e4c57c3aa 100644
> --- a/tests/invalid/require_tailrec_1.m
> +++ b/tests/invalid/require_tailrec_1.m

...

> @@ -74,76 +105,135 @@ odd1(N) =

...

> +:- pragma require_tail_recursion(qsort_1/2).
>
> -qsortapp_1([], []).
> -qsortapp_1([Pivot | T], List) :-
> +qsort_1([], []).
> +qsort_1([Pivot | T], List) :-
>      partition(Pivot, T, [], Left0, [], Right0),
> -    qsortapp_1(Left0, Left),
> -    qsortapp_1(Right0, Right),
> +    qsort_1(Left0, Left),
> +    qsort_1(Right0, Right),
>      append(Left, [Pivot | Right], List).
>
> -:- pragma require_tail_recursion(qsortapp_2/2, []).
> +    % Test the default operation of this pragma when the relevant call
> +    % is in a scope when where the relevant warning is disabled.

Delete "when" there.

> diff --git a/tests/invalid/require_tailrec_2.m b/tests/invalid/require_tailrec_2.m
> index c0d9e1be7..3e0b404ad 100644
> --- a/tests/invalid/require_tailrec_2.m
> +++ b/tests/invalid/require_tailrec_2.m
> @@ -1,12 +1,14 @@
>  %---------------------------------------------------------------------------%
>  % vim: ft=mercury ts=4 sw=4 et
>  %
> -% Tests of `pragma require_tail_recursion' with
> -% `--warn-non-tail-recursion self'.
> +% The .exp  file is for LLDS grades that allow tail recursion.
> +% The .exp2 file is for MLDS grades that allow tail recursion.
> +% The .exp3 file is for grades without tail recursion (.debug, .profdeep).
>  %
> -% The .exp file is for non-deep-profiling LLDS grades.
> -% The .exp3 file is for deep profiling LLDS grades.
> -% The .exp2 file is for MLDS grades.
> +% This is a copy of the require_tailrec_a test case. Whereas that test case

You mean require_tailrec_1 there (although as per above, I suggest renaming
both test case anyway.)

The rest looks fine.

Julien.


More information about the reviews mailing list