[MLton] cvs commit: added flags -show-def-use, -warn-unused
Matthew Fluet
fluet@cs.cornell.edu
Tue, 17 Feb 2004 09:56:29 -0500 (EST)
> -warn-unused reports all identifiers that have no uses, with a few
> exceptions to cut down on spurious warnings. First, identifers that
> are still in scope are not reported. Second, identifiers that are
> defined in functor bodies of unused functors are not reported if they
> are either exported by the functor or are passed as arguments to other
> functors. Third, types defined as datatypes are not reported, since
> often the constructors are used but the type is not.
>
> There are still some more changes that will help cut down on spurious
> warnings and will improve the output for -show-def-use. But things
> are working well enough that I'd like feedback. Please try out
> -show-def-use and -warn-unused on your programs and see what you
> think.
In the following:
fun app f i [] = []
| app f i (x::xs) = (f(i,x); app f (i + 1) xs)
mlton -warn-unused true reports that f and i in the first case are
unused. I guess that is technically true, but I would never write the
function as:
fun app _ _ [] = []
| app f i (x::xs) = (f(i,x); app f (i + 1) xs)
I don't know if it is possible to merge the def-use information for
function arguments from different cases, but that would seem to be one
source of spurious errors. In such a function definition, I would care to
know that an argument was unused in all cases, but not that an argument
was unused in an individual case.
Another related idiom would be to always name the components of a
datatype, even if they are unused:
fun head (x::xs) = x
| head _ => raise Fail "head"
I'm not sure that there would be many non-spurious warnings here.