[MLton] False unused warnings with functors

Matthew Fluet fluet at tti-c.org
Thu Nov 1 10:31:24 PST 2007


On Tue, 9 Oct 2007, Vesa Karvonen wrote:
> Consider the following minimal example:
>
> functor Warning (type t val x : t) = struct
>   val y = x
> end
>
> structure X = Warning (type t = int val x = 1)
>
> Compiling the above with -default-ann 'warnUnused true' gives the
> following warning:
>
> Warning: /home/vk/work/sml/sandbox/unused-warning.sml 5.29.
>  Unused type: t.
>
> The problem with the warning here is that the definition is used.  It
> just isn't explicitly referred to within the body (rhs) of the
> functor.  It is only used within the argument signature.

I created a new page
   http://www.mlton.org/WarnUnusedAnomalies
to collect perceived anomalies with the warnUnused annotation.

One thing that is going on is that matching a signature component is not 
considered a use of the component.  This can certainly lead to some 
anomalies, in the sense that it is not the case that deleting a binding 
that is warned as unused from a well-typed program will yield a well-typed 
program.

Another issue is that warnUnused really serves two, slightly different 
purposes.  One purpose is to identify likely bugs; this is the common case 
of unused warnings in code like:

   fun map f l =
     case l of
        nil => nil
      | h::t => (f h) :: (map f l)

The warning that t is unused is useful to identify the bug in this code.
This purpose is pretty agnostic on the question of whether matching a 
signature should be considered a use.

The other purpose is to identify dead code for the purposes of code 
maintenance.  For this purpose, it is useful to consider matching a 
signature as not a use.  It can help identify structure and signature 
components that can be eliminated.

Both purposes have their utility, but they are slightly different in their 
focus.

There is also the implementation of the def-use information and the 
def-use mode.  For example, if one were to consider signature matching as 
a use of the component, what source location should be recorded for the 
use site?  Under the current implementation, I believe that every use site 
of a type or value corresponds to a source location where the syntactic 
token is the symbol in question (possibly at the end of a structure path).
Should the use site due to matching be the signature ascription site? the 
component in the declaration of the signature?

Nontheless, I think there are clear avenues of improvement for the 
warnUnused and def-use infrastructure.  Please add other suggestions for 
improvement to the WarnUnusedAnomalies page.

> I've run into this warning several times earlier.  Often subsequent
> changes to the code eliminated the warning.  Currently some code in my
> generics library causes warnings for similar reasons (except that the
> definition is a substructure containing types rather than just a
> type).
>
> I haven't yet looked at the code (in MLton) to see whether this would
> be easy to fix.
>
> -Vesa Karvonen
>
> _______________________________________________
> MLton mailing list
> MLton at mlton.org
> http://mlton.org/mailman/listinfo/mlton
>



More information about the MLton mailing list