[m-rev.] for review: --warn-unused-types

Julien Fischer jfischer at opturion.com
Sun Feb 15 01:18:19 AEDT 2026


On Sat, 14 Feb 2026 at 11:37, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
> For review by anyone.
>
> I am particularly seeking feedback on the XXX at the end of the
> log file, which I plan to either act on or delete, depending on
> your opinions, before commit. To help you decide, you should
> see the diffs to the .err_exp files in tests/warnings, and see whether
> you think the new warnings there are do more to help or to distract.

> Add a new option, --warn-unused-types.

Add a brief description of what the new option does here.

> compiler/options.m:
>     Add the new option.

...

> tests/warnings/warn_dead_procs.err_exp:
>     Expect the new warnings for unused types.
>
>     Some of those types are unused *only* because the code
>     that is intended to use them is itself incorrect, and it is
>     incorrect in a way that prevents the uses of types from being
>     recorded in the HLDS.
>
>     XXX Do we want to shut up these warnings? We could do so
>     by moving the new code in typecheck.m to mercury_compile_front_end.m,
>     and make it test not just for the presence of type errors,
>     but *any* errors, before disabling the new option.

When I started looking at this diff, I would have said no, but having
looked at the bigtest example, below I think would now say yes.

> diff --git a/library/rtti_implementation.m b/library/rtti_implementation.m
> index 99414ec67..685aa4688 100644
> --- a/library/rtti_implementation.m
> +++ b/library/rtti_implementation.m
> @@ -4170,12 +4170,6 @@ get_remote_secondary_tag(_) = 0 :-
>      ;       stag_remote
>      ;       stag_variable.
>
> -:- type du_sectag_alternatives ---> du_sectag_alternatives(c_pointer).
> -:- pragma foreign_type("C#", du_sectag_alternatives,
> -    "runtime.DuFunctorDesc[]").
> -:- pragma foreign_type("Java", du_sectag_alternatives,
> -    "jmercury.runtime.DuFunctorDesc[]").
> -

That may simply be a result of library/rtti_implementation being incomplete.

> diff --git a/tests/invalid_nodepend/bigtest.err_exp b/tests/invalid_nodepend/bigtest.err_exp
> index 0e52a32e6..98c58a20e 100644
> --- a/tests/invalid_nodepend/bigtest.err_exp
> +++ b/tests/invalid_nodepend/bigtest.err_exp
> @@ -21,5 +21,6 @@ bigtest.m:010: Syntax error at token ':-': operator precedence error.
>  bigtest.m:013: Error:  [38;5;87m`incorrect_declaration' [39;49m is  [38;5;203mnot a valid declaration type. [39;49m
>  bigtest.m:015: Error: predicate  [38;5;87m`p'/1 [39;49m  [38;5;203mhas no mode declaration. [39;49m
>  bigtest.m:015:   (Use `--infer-modes' to enable mode inference.)
> +bigtest.m:025: Warning: type constructor `t2'/0 is  [38;5;203munused. [39;49m

Given that this test lacks module, interface and implementation declarations,
I'm not sure you can say that t2/0 is a local type or not.

>  bigtest.m:030: Error: in definitions of equivalence types,  [38;5;40mthe type name must [39;49m
>  bigtest.m:030:    [38;5;40mbe followed by `==', [39;49m not  [38;5;203m`='. [39;49m

...

> diff --git a/tests/warnings/help_text.err_exp b/tests/warnings/help_text.err_exp
> index 039f38338..349eabb59 100644
> --- a/tests/warnings/help_text.err_exp
> +++ b/tests/warnings/help_text.err_exp
> @@ -904,6 +904,10 @@ Warning options
>          Warn about modules that are imported in the interface of a parent
>          module, but not used in the interface of that module.
>
> +    --no-warn-unused-types
> +        Warn about types that are neither used in their defining module nor
> +        exported to other modules.

I don't think this should be enabled by default. Most of the other warnings
for unused things are off by default. I can see this being slightly annoying
if I am trying to sketch out a module's types before writing the code that
uses them.

The diff looks fine otherwise.

Julien.


More information about the reviews mailing list